Article View: comp.unix.shell
Article #287Re: user real name
From: Tom Christiansen
Date: Tue, 04 Aug 1992 16:30
Date: Tue, 04 Aug 1992 16:30
44 lines
1916 bytes
1916 bytes
From the keyboard of m23364@mwunix (James Meritt):
:It's no big deal to get the real name of the person who is executing a script
:(to me, anyway) UNLESS the system is using yellow pages. How do I then?
:otherwise, I just use:
: grep $user /etc/passwd | cut -d: -f5
Try:
user=${LOGNAME-${USER-`whoami`}}
if [ x`domainname` = x ]; then
ypmatch $user passwd
else
grep $user /etc/passwd
fi | cut -d: -f5 | sed -e 's/,.*//' -e 's/&/$user/g'
Although it would be better to avoid cut. You can do it all in sed
anyway, and not everyone has cut, so turn the fi line into:
fi | sed -e "s/[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*/\1/
s/,.*//
s/&/$user/g"
Using perl:
#!/usr/bin/perl
($login, $name) = (getpwuid($>))[0,6];
$name =~ s/,.*//;
$name =~ s/&/$login/g;
print "$name\n";
or simply
perl -le 'print ((getpwuid($>))[6] =~ /([^,]+)/)'
If you don't care about &-processing.
e-tom
--
Tom Christiansen tchrist@convex.com convex!tchrist
"My employer does not necessarily share my views - but I'm working on it."
Technical Details
Message-ID:
<1992Aug4.163057.26780@news.eng.convex.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!convex!convex!tchristReferences:
<1992Aug4.153431.845@linus.mitre.org>Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.shell
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!cs.utexas.edu!convex!convex!tchrist
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: user real name
Originator: tchrist@pixel.convex.com
Sender: usenet@news.eng.convex.com (news access account)
Message-ID: <1992Aug4.163057.26780@news.eng.convex.com>
Date: Tue, 4 Aug 1992 16:30:57 GMT
Distribution: usa
Reply-To: tchrist@convex.COM (Tom Christiansen)
References: <1992Aug4.153431.845@linus.mitre.org>
Nntp-Posting-Host: pixel.convex.com
Organization: CONVEX Realtime Development, Colorado Springs, CO
X-Disclaimer: This message was written by a user at CONVEX Computer
Corp. The opinions expressed are those of the user and
not necessarily those of CONVEX.
Lines: 44