Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!ucsd!ucbvax!decwrl!sun!gorodish!guy From: guy@gorodish.Sun.COM (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: accessing shell variables from within awk? Message-ID: <69058@sun.uucp> Date: 20 Sep 88 03:32:31 GMT References: <473@diamond.unix.ETA.COM> Sender: news@sun.uucp Distribution: na Lines: 27 > 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. Does any version of awk > have a shortcut to get at it's environment? Well, the "new awk" might, but I don't know how many UNIX systems offer it yet. "awk" doesn't have any mechanism for getting at the UNIX environment (i.e., the thing that "export" in the Bourne and Korn shells, and "setenv" in the C shell, affect). You can put assignments on the command line: "awk" variables may be set on the command line using arguments of the form "variable=value". This sets the "awk" variable "variable" to "value" before the first record of the next filename argument is read. which might be a way to pass them to "awk", e.g. awk -f awkfile foo="$foo" which sets the "awk" variable "foo" to the value of the shell variable "foo". > BTW, I'm running SunOS 3.5, if it matters much. Not a lot; that "awk" is basically the S5R2 "awk", but the feature in question is, I think, in the 4BSD "awk" as well.