accessing shell variables from within awk?

Miles O'Neal meo at stiatl.UUCP
Wed Sep 21 22:35:25 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"? ...

As a matter of fact, this is from a Sun 386i running 4.0,
but should work with any real awk. We use it also under System V on
a Convergent.

usernum=`awk -F: '/^'$1'/ { print $3 }' /etc/passwd

This is from a Bourne shell script we use. The $1 could just as
easily be $fred or any variable name.



More information about the Comp.unix.questions mailing list