Path: utzoo!attcan!uunet!pyrdc!prcpto!pdvbld From: pdvbld@prcpto.UUCP (Betsy Dunphy) Newsgroups: comp.unix.questions Subject: Re: accessing shell variables from within awk? Summary: to quote or not to quote...... Message-ID: <313@prcpto.UUCP> Date: 26 Sep 88 19:38:57 GMT References: <473@diamond.unix.ETA.COM> Distribution: na Organization: EMHART/PRC McLean, VA Lines: 30 > 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)}' $HOME is expanded by the shell by the notation of the single-quotes. The trick is the double-quotes - these denote the result as a string. Otherwise, the value of $HOME would be treated as a variable (an unitialized variable). This works in both bourne shell and csh (of course! :-)) and was tried on both a Masscomp 5500 3.1.B RTU and SUN 3/160 under 3.2. --------------------------------------------------------------------- Betsy Dunphy | PRC | 600 West Services Road | The usual disclaimer here...... Washington, DC 20041 | 703-883-5138 | prcpto@pdvbld.UUCP | ---------------------------------------------------------------------