Newsgroups: comp.unix.wizards
Path: utzoo!utgpu!trigraph!briand
From: briand@trigraph.uucp (Brian Dickson)
Subject: Re: awk arguments
Message-ID: <1990Jul24.235105.17238@trigraph.uucp>
Keywords: awk
Reply-To: briand@trigraph.UUCP (Brian Dickson)
Organization: Trigraph Inc., Toronto, Canada
References: <290@sun13.scri.fsu.edu>
Date: Tue, 24 Jul 90 23:51:05 GMT

In article <290@sun13.scri.fsu.edu> mayne@VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) writes:
>Since unix file names may contain an = this is clearly ambiguous.
>
>[...]
>
>The practical problem this raises is how to communicate an
>argument value or a value calculated by a script file into
>an awk program embedded in a script file. Referencing $n in
>the quoted awk program won't work, since awk will think that
>refers to field number n.
>
>... Surely I have missed something obvious. There must be a 
>better way. I would be most grateful if someone would suggest one.

The problem is, ''-quotes hide special characters, which is why they
are often used. ""-quotes don't, thus letting shell substitutions occur.
But, you say, I want to use the $ in my awk script; how do I hide it from
the shell? The \ character inside "" will hide \,',", and $.
(Paraphrased from sh(1) on BSD4.3)

So, for example, the following script will take $1 as an assignment, $2
as a file, and run an awk script making use of the various combinations of
references to shell and awk variables.

	eval $1
	awk "{print \$0 \" $X $1 $2\"}" <$2

Call the file X=Y, and make it executable; see what "X=Y X=Y X=Y" does.

>
>... Are there better versions out there?
At our site we use nawk, which I believe is public domain. Consult an archive
site near you for more info.

--
Brian Dickson,
Trigraph Inc.
Disclaimer: Disclaimer is a trademark of AT&T.
