]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
* src/groups.sh: When invoked with 0 or 1 argument, just exec "id".
authorJim Meyering <jim@meyering.net>
Tue, 26 Sep 2006 09:46:35 +0000 (09:46 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 26 Sep 2006 09:46:35 +0000 (09:46 +0000)
Rewrite to avoid using temporary, $status.

ChangeLog
src/groups.sh

index 7586f546266137a65f54bb3d4f30af39b4a83484..c9e95221209059e14761a25dbbf8182c07ebb2af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-09-26  Jim Meyering  <jim@meyering.net>
 
+       * src/groups.sh: When invoked with 0 or 1 argument, just exec "id".
+       Rewrite to avoid using temporary, $status.
+
        * NEWS: Mention the bug fix.
        * src/groups.sh: Don't hide a write failure.
        Reported by Iain Calder <ic56@rogers.com>.
index dc64d12f1e5204856a2676af0989bec9cb0cabcd..43395d710d03ab4b53e40b3b7b53db9e9576b0e5 100755 (executable)
@@ -53,18 +53,17 @@ case $# in
   * ) ;;
 esac
 
-if [ $# -eq 0 ]; then
-  id -Gn
-  fail=$?
-else
-  for name in "$@"; do
-    groups=`id -Gn -- $name`
-    status=$?
-    if test $status = 0; then
-      echo $name : $groups || fail=1
-    else
-      fail=$status
-    fi
-  done
-fi
+# With fewer than two arguments, simply exec "id".
+case $# in
+  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
+  else
+    fail=1
+  fi
+done
 exit $fail