Last active
April 20, 2020 01:28
-
-
Save spchamp/fadb088c46e2e397a451ce462b54a352 to your computer and use it in GitHub Desktop.
print a list of a auxiliary groups assigned to a single user name, using getent(1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# getent_auxgroups.sh - print auxiliary groups assigned to a single user name | |
# | |
# % Environment parameters | |
# WHOM | |
# - user name to parse for | |
# - If unspecified, defaults to $USER | |
# - Will be interpreted within a regular expression, in awk(1) | |
# | |
# % Depends On | |
# - getent(1) | |
# - awk(1) | |
# | |
# % See Also | |
# - pw(8), FreeBSD System Manager's Manual | |
# | |
# Public Domain | |
# | |
getent group | | |
awk -v UNAME="${WHOM:-${USER}}" \ | |
'BEGIN { FS=":" } | |
{ split(4,subfield,/,/); | |
for (idx in subfield) { | |
if (match($subfield[idx],"^" UNAME "$")) { | |
print $1 | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment