:
# groups: list users in groups.  Expects USER to be set to user's login name.
# @(#) groups.sh 1.0 90/05/29
# 90/05/29 john h. dubois iii (john@armory.com)

case "$1" in
	"-f") everyone=true; shift;;
	"-h") echo \
"groups: list supplemental groups users belong to at login time.
Syntax: groups [-f] [ user ... ]
If no users are given, the user running groups is used.
If -f is given, the group name, its password (if any),
its group id, and everyone in the groups is listed;
if not, only the group names are listed.
egrep-style syntax may be used to match users,
if escaped from the shell."; exit 0;;
	-*)  echo "groups: invalid flag '$1'.  Use -h for help."; exit 1;;
esac

if [ $# -eq 0 ]; then
	names=$USER
else
	names="$1"
	shift
	while [ $# -gt 0 ]; do
		names="$names|$1"
		shift
	done
	names="($names)"
fi

names="[:,]$names([, \t]|$)"

if [ -n "$everyone" ]; then
	egrep "$names" /etc/group
else
	egrep "$names" /etc/group | sed 's/:.*//'
fi
