From: dumser AT lesol1 DOT dseg DOT ti DOT com (James Dumser) Subject: Re: awk acting funny 28 Oct 1996 08:37:38 -0800 Sender: daemon AT cygnus DOT com Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <199610281419.IAA13892.cygnus.gnu-win32@lesol1.dseg.ti.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Original-To: reed AT engr DOT orst DOT edu Original-Cc: gnu-win32 AT cygnus DOT com In-Reply-To: from "Brandon Reed" at Oct 26, 96 03:25:15 pm X-Mailer: ELM [version 2.4 PL23] Content-Length: 1901 Original-Sender: owner-gnu-win32 AT cygnus DOT com On Sat, 26 Oct 1996 15:25:15 -0700 (PDT), Brandon Reed wrote: >On Sat, 26 Oct 1996, David Jeffers wrote: >> Hmmm. I use B16, bash, and Win95 and the above program >> works fine for me...question which 'gawk.exe' are you >> using? Cygnus port or ?? > >It's the cygnus port, If it works fine under the bash shell then I'll just >use that. I just figured that it was ported to run abnormally on >the dos command line for some odd reason ( like to get around some dos >bug). Since it was gawk that was giving the error, not the command shell I >figured there was some reason to change the behavior. gawk isn't broken. bash isn't broken. If anything is "broken," it's COMMAND.COM (CMD.EXE) [DOS shell] -- actually it's just different. gawk does not interpret the single quotes; that's the shell's job. DOS shell does not understand single quotes so it passes them to the gawk as is. dir | gawk '{print "hello " $1}' should get passed to gawk as a single argument, "{print \"hello \" $1}" (the single quotes limit interpretation of the argument). "{print $1}" gets passed to gawk correctly so it works, but trying to put a literal in the print string (e.g., {print "hello " $1}) doesn't work because DOS shell interprets and strips out double quotes -- gawk "{print "hello " $1}" turns into a number of arguments passed to gawk ("{print ", "hello", " $1}") whereas gawk expects the program to be a single argument. Replacing "hello " with 'hello ' doesn't work because gawk doesn't do single quotes. Replacing "hello " with hello also doesn't work like you want (it does work) because gawk would then interpret hello as a variable whose value is probably null. So the bottom line is if you want to run your gawk script from a DOS shell, you will probably need to read your gawk program from a file (gawk -f pgm.awk). -- James Dumser 972-462-5335 dumser AT ti DOT com - For help on using this list, send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".