Subject: Re: B20.1 sh and bash command line parsing question
From: Chris Faylor <[email-masked]>
To: Rob Tulloh <[email-masked]>
Cc: [email-masked]
Date: Wed, 25 Aug 1999 17:31:14 -0400

I don't know if this helps, but cygwin uses the doubled quote character
'""' to indicate a single quote.  It doesn't recognize the backslash
syntax.

I actually had everything coded to understand the backslash when it was
brought to my attention that a normal MS-DOS application relies on
doubling of quotes to quote a quote.  I know that this is not consistent
with our handling of upper and lower case wildcard characters on the
command line since it means that, in essence, we have different command
line paradigms for quoting and wildcards but now we have backwards
compatibility issues to worry about.

So, maybe someday we'll bite the bullet and make this consistent but,
for now, that's how things work.

Chris Faylor
Win32 Manager
Cygnus Solutions

On Wed, Aug 25, 1999 at 01:04:50PM +0200, Rob Tulloh wrote:
>As a maintainer of GNU make on WIN32 platforms, I am constantly asked
>why Cygwin sh.exe and/or bash.exe don't work correctly when called
>from make. I have a hack that forces all shell commands to be written
>to a temp file and then run via 'sh file'. However, I don't like
>this as it represents a unnecessary performance hit to make on WIN32
>platforms. I have a simple test case that shows the problems.
>
>I am trying to work out why sh.exe and bash.exe are not able to
>be succesfully invoked via 'sh -c' from CreateProcess() for
>all cases of command line. I have
>a simple test example that can be run from the NT command prompt
>which demonstrates the problem. There are 6 lines below which
>use 3 shells to execute 2 different command lines:
>
>> i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
>> i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
>> i:/tools/gk/bin/sh.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
>> i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
>> i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
>> i:/tools/gk/bin/sh.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
>
>The first 2 shells are the ones from the Cygwin B20.1 distribution. The
>3rd shell is Tivoli's custom port of GNU bash to Windows NT. 
>
>> I:\apps\work\cygnus\cygwin-b20>c:\temp\sp2.bat
>> 
>> I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe
>> -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
>> hi
>> 
>> I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.ex
>> e -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
>> hi
>> 
>> I:\apps\work\cygnus\cygwin-b20>i:/tools/gk/bin/sh.exe -c "if [ -d \"c:/temp\" ]
>> ; then echo \"hi\" ; fi"
>> hi
>> 
>> I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe
>> -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
>> Syntax error: Unterminated quoted string
>> 
>> I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.ex
>> e -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
>> there\ ; fi: -c: line 1: unexpected EOF while looking for matching `"'
>> there\ ; fi: -c: line 2: syntax error: unexpected end of file
>> 
>> I:\apps\work\cygnus\cygwin-b20>i:/tools/gk/bin/sh.exe -c "if [ -d \"c:/temp\" ]
>> ; then echo \"hi there\" ; fi"
>> hi there
>
>
>Notice how as soon as white space ("hi there") is introduced into a
>string
>embedded in the command line that 
>the parser breaks down and fails to parse the string correctly. I would
>have thought that the parsing rules would follow the Microsoft C runtime
>rules for argument parsing since it should be possible to invoke Cygwin
>commands from CreateProcess() (natively from Win32) rather than having
>to rely on fork/exec/whatever in cygwin.dll.
>
>Note that I have made the parsing logic within make work for Tivoli's
>custom
>port of bash and also for the MKS version of sh. I am not able to figure
>out what magic is needed to make this work with Cygwin sh or bash. I am
>looking
>for insight on what the parsing algorithm is and how to invoke commands
>from
>WIN32 so that sh/bash can parse them as I would expect. 
>
>Comments?
>
>Thank you,

--
Want to unsubscribe from this list?
Send a message to [email-masked]