Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!netnews.upenn.edu!eniac.seas.upenn.edu!jes
From: jes@eniac.seas.upenn.edu (Joe Smith)
Newsgroups: comp.unix.questions
Subject: Re: accessing shell variables from within awk?
Message-ID: <5321@netnews.upenn.edu>
Date: 27 Sep 88 14:37:17 GMT
References: <473@diamond.unix.ETA.COM> <313@prcpto.UUCP>
Sender: news@netnews.upenn.edu
Reply-To: jes@eniac.seas.upenn.edu.UUCP (Joe Smith)
Distribution: na
Organization: University of Pennsylvania
Lines: 39

In article <313@prcpto.UUCP> pdvbld@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@eniac.seas.upenn.edu			||	Univ. of Penna.     |
|kolakowski%c.chem.upenn.edu@relay.upenn.edu	||	Dept of Chemistry   |
|bcooperman.kolakowski@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@eniac.seas.upenn.edu

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