Subject: Re: awk acting funny
From: [email-masked] (James Dumser)

28 Oct 1996 08:37:38 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Original-To: [email-masked]
Original-Cc: [email-masked]
In-Reply-To: <[email-masked]> from "Brandon Reed" at Oct 26, 96 03:25:15 pm
X-Mailer: ELM [version 2.4 PL23]
Content-Length: 1901      
Original-Sender: [email-masked]

On Sat, 26 Oct 1996 15:25:15 -0700 (PDT), Brandon Reed
  <[email-masked]> 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 [email-masked]
-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".