awk and shell question

Jonathan Bayer jbayer at ispi.UUCP
Sat Sep 16 23:43:16 AEST 1989


HELP!!  I have been pulling my hair out over this seemingly simple
problem:

I have to get the user id, and then get the user description from /etc/passwd.

Now, getting the user id was easy.  The script is below:


LOGNAME=`who am i | awk '{
	logname=$1
	print logname
	}'`


LOGNAME is set nicely here.  However, when I try to do something similar
to /etc/passwd as follows:
a=" awk -F: '\$1 == \"$LOGNAME\" {
	user=\$5;
	print user
	}'"
USER=`cat /etc/passwd | $a`


I get the following error:


awk: syntax error at source line 1
 context is
	 >>> ' <<< 
awk: bailing out at source line 1



Now, the following line does work (when I hardcode in LOGNAME):


USER=`cat /etc/passwd | awk -F: '$1 == "root" { user=$5; print user }'`



So my question is, what am I doing wrong here?  I am not that fluent in awk,
so this doesn't make too much sense right now.

This is running on an SCO Xenix 386, 2.3.3 system.


JB
-- 
Jonathan Bayer		Intelligent Software Products, Inc.
(201) 245-5922		500 Oakwood Ave.
jbayer at ispi.COM		Roselle Park, NJ   07204    



More information about the Comp.unix.wizards mailing list