Subject: awk acting funny
From: [email-masked] (Colin Peters)

30 Oct 1996 03:55:01 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Original-To: [email-masked]
Original-CC: [email-masked], [email-masked], [email-masked]
In-reply-to: DJ Delorie's message of Mon, 28 Oct 1996 20:17:44 -0500 <[email-masked]>
Original-Sender: [email-masked]

> Date: Mon, 28 Oct 1996 20:17:44 -0500
> From: DJ Delorie <[email-masked]>
> 
> > 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.
> 
> COMMAND.COM does absolutely no interpretation of the command line at
> all.  It send it to you as-is, including the space after the command
> name and the carriage return at the end.  It does not know about
> quotes, single or double.  Parsing it is entirely up to the
> application.

Well, yes and no. It is entirely up to the application yes. But most
programmers use the built in parsing provided by their compiler when they
write their 'main' function. After all, somebody splits the arguements up
into that argv array and passes it to main.

In Cygwin ports of gawk, or anything else for that matter, the work gets
done by the cygwin.dll. The dll tries to figure out whether you are running
from bash or not and then processes the command line appropriately. In fact
it does some very heavy processing, expanding wildcarded arguments and, most
likely, quotes and things. More or less it tries to duplicate what bash
does for the application, then it does the more traditional job of splitting
the command line into tokens for main.

> Perhaps what cygnus's gawk is getting is a single argument (argv[1])
> that includes the entire command line, including all the stray quotes,
> as if you had typed this at the unix command line:
> 
> 	  gawk \''{ printf("%d %s\n", $3, $2"); }'\'

I doubt this. I don't think that most of the UNIX tools ported with Cygwin
would understand a single argv[1] with everything from the command line,
and there are many UNIX tools ported with Cygwin which work fine from the
command line. If, on the other hand, you mean that the single quotes might
be included in the argument that is supposed to be quoted here, which is
a mistake in the startup code's tokenization, I agree, that is a distinct
possibility.

It's pretty simple to test. Write a program like this:

main (int argc, char* argv[])
{
	int	x;

	for (x = 1; x < argc; x++)
	{
		printf ("Arg %d: \"%s\"\n", x, argv[x]);
	}
}

And run it with the command line

        test '{ printf("%d %s\n", $3, $2"); }'

And you will see exactly what the cygwin dll has done with that command line.
You might try running it under bash and the ordinary command line, if they're
different then there is a problem that needs fixin'.

If you have the library source from Cygnus you can try digging through it
to find where the command line gets parsed if you are not started from
bash. I think that's where you'll find your problem.

Colin.

P.S. Just out of interest, every compiler startup code I have ever used under
     Win32 or DOS understands double quotes and tokenizes the command line.
     Single quotes is another thing entirely.

------------------------------------------------------------------------------
Colin Peters ------------ Saga Univ. Dept. of Information Science, Saga, JAPAN
http://www.fu.is.saga-u.ac.jp/~colin/home.html - [email-masked]
コリン ピーターズ - 佐賀大学理工学部情報科学科情報基礎学講座
                    - Current favorite kanji: 晴れ 芝生 -

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".