Prefer groups(1).
authorJarkko Hietaniemi <jhi@iki.fi>
Mon, 2 Nov 1998 09:10:33 +0000 (09:10 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 2 Nov 1998 09:10:33 +0000 (09:10 +0000)
id -Gn can be broken.
id -a can save the day.

p4raw-id: //depot/cfgperl@2179

t/op/groups.t

index b2e7663..1eef0bf 100755 (executable)
@@ -2,7 +2,26 @@
 
 $ENV{PATH} = '/usr/xpg4/bin:/bin:/usr/bin:/usr/ucb';
 
-unless (($groups = `(id -Gn || groups) 2>/dev/null`) ne '') {
+# We have to find a command that prints all (effective
+# and real) group names (not ids).  The known commands are:
+# groups
+# id -Gn
+# id -a
+# Beware 1: some systems do just 'id -G' even when 'id -Gn' is used.
+# Beware 2: the 'id -a' output format is tricky.
+
+GROUPS: {
+    last GROUPS if ($groups = `groups 2>/dev/null`) ne '';
+    if ($groups = `id -Gn 2>/dev/null` ne '') {
+       last GROUPS unless $groups =~ /^(\d+)(\s+\d)*$/;
+    }
+    if ($groups = `id -a 2>/dev/null` ne '') {
+       if (/groups=/g && (@g = /\((.+?)\)/g)) {
+           $groups = join(" ", @g);
+           last GROUPS;
+       }
+    }
+    # Okay, not today.
     print "1..0\n";
     exit 0;
 }