lwall@jato.Jpl.Nasa.Gov (Larry Wall) (03/02/90)
In article <426@clover.warwick.ac.uk> alfie@cs.warwick.ac.uk (Nick Holloway) writes: : I saw a request somewhere for a program like the SysV id(1). I got used : to it under SunOS, and so I wrote this one to use on our BSD machines. : As far as I can tell, they act identically - though I can't check this, : since I do not have access to source. The only area they may differ is : if the user or group name can not be determined. For those of you who can't remember where you keep .c files, here's the one I use. It differs slightly in that it sorts the groups. #!/usr/bin/perl print "uid=$<"; print "($name)" if ($name) = getpwuid($<); print " gid=", $( + 0; print "($name)" if ($name) = getgrgid($(); if ($> != $<) { print " euid=$>"; print "($name)" if ($name) = getpwuid($>); } if ($) != $() { print " egid=", $) + 0; print "($name)" if ($name) = getgrgid($)); } @groups = split(' ',$(); shift(@groups); for (@groups) { $_ .= "($name)" if ($name) = getgrgid($_); } print " groups=", join(',',sort bynum @groups) if @groups; print "\n"; sub bynum { $a - $b; } No doubt Randal could write it shorter... Larry
merlyn@iwarp.intel.com (Randal Schwartz) (03/03/90)
In article <2964@jato.Jpl.Nasa.Gov>, lwall@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? print pack('C25',grep($_ = 32 + y/ / /, split(/\n/, <<END))); X X X X X X X X X X X X X X X X X X X X X X X X X END -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
lwall@jato.Jpl.Nasa.Gov (Larry Wall) (03/03/90)
In article <1990Mar2.210209.11209@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: : In article <2964@jato.Jpl.Nasa.Gov>, lwall@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,@gr)))x($#gr>=0); Though I'll admit readability suffers slightly... Larry
" Maynard) (03/06/90)
In article <2969@jato.Jpl.Nasa.Gov> lwall@jato.Jpl.Nasa.Gov (Larry Wall) writes: >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,@gr)))x($#gr>=0); > >Though I'll admit readability suffers slightly... main() { puts("Good God. What next - an Obfuscated Perl Contest??"); } -- Jay Maynard, EMT-P, K5ZC, PP-ASEL | Never ascribe to malice that which can jay@splut.conmicro.com (eieio)| adequately be explained by stupidity. {attctc,bellcore}!texbell!splut!jay +---------------------------------------- "Klein bottle for sale. Inquire within." - Charles Hannum
allbery@NCoast.ORG (Brandon S. Allbery) (03/10/90)
As quoted from <0-H+Z_@splut.conmicro.com> by jay@splut.conmicro.com (Jay "you ignorant splut!" Maynard): +--------------- | main() { | puts("Good God. What next - an Obfuscated Perl Contest??"); | } +--------------- main() { cout << "That's what the signature scripts are, silly! ;-)\n"; } -- Brandon S. Allbery (human), allbery@NCoast.ORG (Inet), BALLBERY (MCI Mail) ALLBERY (Delphi), uunet!cwjcc.cwru.edu!ncoast!allbery (UUCP), B.ALLBERY (GEnie) BrandonA (A-Online) ("...and a partridge in a pear tree!" ;-)