From d0f88fcc9c7c03c807a5815903c49287c8492866 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Mon, 2 Nov 1998 09:10:33 +0000 Subject: [PATCH] Prefer groups(1). id -Gn can be broken. id -a can save the day. p4raw-id: //depot/cfgperl@2179 --- t/op/groups.t | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/t/op/groups.t b/t/op/groups.t index b2e7663..1eef0bf 100755 --- a/t/op/groups.t +++ b/t/op/groups.t @@ -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; } -- 2.7.4