accessing shell variables from within awk?

Jim Frost madd at bu-cs.BU.EDU
Thu Sep 29 14:47:14 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 simplest way is:

set shellvar = "foo"

awk 'BEGIN { foo == ' $shellvar ' ; \
             print  foo             \
           }'

You could similarly unquote and quote for every occurance of "foo".

jim frost
madd at bu-it.bu.edu



More information about the Comp.unix.questions mailing list