accessing shell variables from within awk?

Chuck Karish karish at hanauma.stanford.edu
Tue Sep 20 14:45:02 AEST 1988


In article <473 at diamond.unix.ETA.COM> rscott at eta.unix.ETA.COM (Rich Scott)
writes:
>	How can I access a shell variable (to wit, a few environment
>variables) from within "awk"?

The awk command is usually written inside single quotes.  Use more
quotes to expose the shell variables you need.  The following program will
print a user's name and user ID number:

USRNAME="fred"
export USRNAME

awk -F':' '$1 ~ /'$USRNAME'/{print $1, $3}' /etc/passwd

Chuck Karish    ARPA:   karish at denali.stanford.edu
                UUCP:   {decvax,hplabs!hpda}!mindcrf!karish
                USPS:   1825 California St. #5   Mountain View, CA 94041



More information about the Comp.unix.questions mailing list