awk and shell question

Richard O'Keefe ok at cs.mu.oz.au
Mon Sep 18 23:02:59 AEST 1989


In article <2412 at netcom.UUCP>, hinton at netcom.UUCP (Greg Hinton) writes:
: In article <1163 at ispi.UUCP> jbayer at ispi.UUCP (Jonathan Bayer) writes:
: >I have to get the user id, and then get the user description from /etc/passwd.

: How about this:
: grep \^`who am i | cut -d' ' -f1`\: /etc/passwd | cut -d: -f5

Watch out for BSD-derived systems, where the first "word" from the
"who am i" command has the form "machine!user", e.g. munmurra!ok.
You want the bit after the !.  A much simpler method is to use a shell
variable.  Check "environ" in the manual, and you'll find that you have
	LOGNAME		# System V
or	USER		# BSD
or both.  Just do
	grep "^${LOGNAME}:" /etc/passwd | what-ever-you-want-here
Again, watch out for Yellow Pages; if you're using that you have to do
	ypcat passwd | grep "^${LOGNAME}" | what-ever-you-want-here



More information about the Comp.unix.wizards mailing list