summaryrefslogtreecommitdiff
path: root/src/groups.sh
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-09-26 19:11:25 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-09-26 19:11:25 +0000
commitb7c315cdda2d1d189232c2cd36f3b2610914e5f3 (patch)
tree46cf5c041e19fc90f8a4571ac638f20291726d2c /src/groups.sh
parent412a3ca0b0e87c1be185aa344adff347a7559736 (diff)
downloadcoreutils-b7c315cdda2d1d189232c2cd36f3b2610914e5f3.tar.xz
[ChangeLog]
* NEWS: "groups user" no longer outputs "user :"; you need at least two users. "groups" now processes options like --help more compatibly. * src/groups.sh: Implement the option-processing change. Handle user and group names with special characters more robustly. Report write errors instead of exiting silently with status 1. [doc/ChangeLog] * coreutils.texi (groups invocation): "groups" no longer prefixes the output with "user :" unless more than one user is specified.
Diffstat (limited to 'src/groups.sh')
-rwxr-xr-xsrc/groups.sh53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/groups.sh b/src/groups.sh
index 43395d710..decbe6aaf 100755
--- a/src/groups.sh
+++ b/src/groups.sh
@@ -34,36 +34,49 @@ Report bugs to <@PACKAGE_BUGREPORT@>."
version='groups (@GNU_PACKAGE@) @VERSION@
Written by David MacKenzie.
-Copyright (C) 2004 Free Software Foundation, Inc.
+Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
-fail=0
-case $# in
- 1 )
- case "z${1}" in
- z--help )
- echo "$usage" || fail=1; exit $fail;;
- z--version )
- echo "$version" || fail=1; exit $fail;;
- * ) ;;
- esac
- ;;
- * ) ;;
-esac
+for arg
+do
+ case $arg in
+ --help | --hel | --he | --h)
+ exec echo "$usage" ;;
+ --version | --versio | --versi | --vers | --ver | --ve | --v)
+ exec echo "$version" ;;
+ --)
+ shift
+ break ;;
+ -*)
+ echo "$0: invalid option: $arg" >&2
+ exit 1 ;;
+ esac
+done
# With fewer than two arguments, simply exec "id".
case $# in
- 0|1) exec id -Gn "$@" ;;
+ 0|1) exec id -Gn -- "$@" ;;
esac
# With more, we need a loop, and be sure to exit nonzero upon failure.
-for name in "$@"; do
- if groups=`id -Gn -- $name`; then
- echo $name : $groups || fail=1
+status=0
+write_error=0
+
+for name
+do
+ if groups=`id -Gn -- "$name"`; then
+ echo "$name : $groups" || {
+ status=$?
+ if test $write_error = 0; then
+ echo "$0: write error" >&2
+ write_error=1
+ fi
+ }
else
- fail=1
+ status=$?
fi
done
-exit $fail
+
+exit $status