Cygwin bash -c yields different argc depending on whether the command start with c:/ or something else Cygwin bash -c yields different argc depending on whether the command start with c:/ or something else shell shell

Cygwin bash -c yields different argc depending on whether the command start with c:/ or something else


This probably has to do with the way bash handle its parameters. Actually, we need to take a look on bash's source code to assure what's really happening, but you can be sure the reason for this strange behavior is there.

I made this conclusion based on the way Windows handles double quotes and slashes. Windows does not handle strings the same way Unix-like systems do. Shortly, there is no way to escape double-quotes inside double-quoted strings.

In order to ensure this, create a file named test.bat on Windows with this content:

@echo offecho %1

And invoke it passing your parameter:

C:\> test.bat "c:/cygwin/home/jonathan/camlprog \"foo\" bar"

As result you will get:

"c:/cygwin/home/jonathan/camlprog \"foo\" bar"

Which means the slashes and all other characters are passed to script. So, in your case, they are being passed to bash, which is handling these characters for you, and it is doing this in some inconsistent way.

So, to workaround your problem, you can invoke your command this way:

 c:\> c:\cygwin\bin\bash -c 'c:/cygwin/home/jonathan/camlprog "foo" bar' foo bar

Using single quotes first and double quotes later, the script camlprog seems to run as expected.