Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!texsun!smunews!necssd!harrison From: harrison@necssd.NEC.COM (Mark Harrison) Newsgroups: comp.unix.questions Subject: Re: How to pass shell variables to awk? Message-ID: <762@necssd.NEC.COM> Date: 10 Apr 91 14:07:10 GMT References: <1991Apr8.223119.2318@elroy.jpl.nasa.gov> Organization: NEC America Inc. SSD, Irving, TX Lines: 68 In article <1991Apr8.223119.2318@elroy.jpl.nasa.gov>, pjs@euclid.jpl.nasa.gov (Peter Scott) writes: > Maybe this one should be in the FAQ; I will submit the following text to the FAQ list... Question: How do I submit a FAQ to the FAQ list? :-) # # This shell script provides several answers to the question # "How can I pass shell variables to awk?" # foo=123 bar=456 foostr=hello barstr=world twowords="hello world" # 1. Surround the environment variables with single quotes. This # causes awk's first argument to be a single string, composed # of quoted strings interspersed with values of shell variables. # They are treated as one argument because there are no unquoted # spaces. awk 'BEGIN {print 1, '$foo' + '$bar'}'