accessing shell variables from within awk?

Andy Behrens finn at eleazar.dartmouth.edu
Sat Sep 24 11:20:19 AEST 1988


In answer to the question "How can I access a shell variable from within
awk", guy at gorodish.Sun.COM (Guy Harris) writes:
>
> You can put assignments on the command line,
> which might be a way to pass them to "awk", e.g.
>
>	awk -f awkfile foo="$foo"

If you are going to use this feature, be aware that many versions of awk
only recognize command-line assignments if they are followed by at least
one filename.  If you want awk to read from the standard input, explicitly
name it with '-', e.g.

	ls -l | awk -f awkfile foo="$foo" -

--
"Christ died for our sins.  Dare we make his martyrdom meaningless by
not committing them?"
					Andy Behrens
					andyb at burcoat.uucp
					(soon: andyb at coat.uucp)

internet: andyb%coat at dartmouth.edu
uucp:     {harvard,decvax}!dartvax!coat!andyb
bitnet:   andyb%coat at dartcms1
RFD 1, Box 116, East Thetford, Vt. 05043		 (802) 649-1258



More information about the Comp.unix.questions mailing list