This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

B20.1 sh and bash command line parsing question


Hello,

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,

Rob Tulloh

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]