Version of id(1).
Larry Wall
lwall at jato.Jpl.Nasa.Gov
Sat Mar 3 09:50:23 AEST 1990
In article <1990Mar2.210209.11209 at iwarp.intel.com> merlyn at iwarp.intel.com (Randal Schwartz) writes:
: In article <2964 at jato.Jpl.Nasa.Gov>, lwall at jato (Larry Wall) writes:
: [21 lines of code deleted...]
: | No doubt Randal could write it shorter...
:
: Well, OK, taking on the challenge, how about:
:
: #!/usr/bin/perl
: sub u { local($name)=getpwuid($_[0]); $name && "($name)";}
: sub g { local($name)=getgrgid($_[0]); $name && "($name)";}
: sub bynum { $a - $b; }
: print "uid=$<",&u($<);
: print " gid=", $(+0,&g($();
: print " euid=$>",&u($>) if $> != $<;
: print " egid=", $)+0,&g($)) if $) != $(;
: @groups=split(' ',$(); shift(@groups);
: print " groups=", join(',',sort bynum grep(($_ .= &g($_)) || 1, @groups))
: unless $#groups < $[;
: print "\n";
:
: Something like that, Larry?
That's not short. This is short: :-)
#!/usr/bin/perl
@n=('pwu','grg');sub n{local($n)=eval"get$n[$_[1]]id(\$_[0])";$n&&"($n)";}sub nm
{$a-$b;}@gr=split(' ',$();$g=shift(@gr);$\="\n";print"uid=$<",&n($<)," gid=",$g,
&n($(,1),(" euid=$>".&n($>))x($<!=$>),(" egid=".$)+0 .&n($),1))x($(!=$)),
(" groups=".join(',',sort nm grep(($_.=&n($_,1))||1, at gr)))x($#gr>=0);
Though I'll admit readability suffers slightly...
Larry
More information about the Alt.sources
mailing list