accessing shell variables from within awk?

Joe Smith jes at eniac.seas.upenn.edu
Wed Sep 28 00:37:17 AEST 1988


In article <313 at prcpto.UUCP> pdvbld at prcpto.UUCP (Betsy Dunphy) writes:
>> How can I access a shell variable (to wit, a few environment
>> variables) from within "awk"? I've tried various combinations of
>> shell quoting, and whatnot, to no avail.......
>
>As I understand the question, the writer desires to be able to
>use environmental variables in awk functions like printf.  The following
>example prints file paths: 
>
>        ls | awk '{printf("%s/%s\n","'$HOME'",$1)}'
>
The example posted here is *not* expansion of shell variables "within"
awk, but instead expansion of shell variables on the command line, which we
all know is possible.

According to the book "The Awk Programming Language" A. Aho et al., none
of the shell variables are accessible from within the language. So the only
option is to use the shell as a preprocessor as in the above example.


Frank Kolakowski (a.k.a. Lee)
____________________________________________________________________________
|c/o jes at eniac.seas.upenn.edu			||	Univ. of Penna.     |
|kolakowski%c.chem.upenn.edu at relay.upenn.edu	||	Dept of Chemistry   |
|bcooperman.kolakowski at bionet-20.arpa		||	231 South 34th St.  |
|AT&T:	1-215-898-2927				||	Phila, PA 19104     |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Well, O.K. I'll compromise with my principles because of EXISTENTIAL DESPAIR!
=============================================================================


Joe Smith
jes at eniac.seas.upenn.edu

University of Pennsylvania
Department of Chemistry
231 S. 34th Street
Philadelphia, PA 19104
(215) 898-4797



More information about the Comp.unix.questions mailing list