I’m in a Windows prompt, i.e. cmd.exe; “camlprog” does nothing but print its arguments (i.e. argv) separated by “\n” (i.e. each one on its own line).
First case:
c:\> c:\cygwin\bin\bash -c "c:/cygwin/home/jonathan/camlprog \"foo\" bar"
c:\cygwin\home\jonathan\camlprog.exe
foo bar
Second case:
c:\> c:\cygwin\bin\bash -c "~/camlprog \"foo\" bar"
c:\cygwin\home\jonathan\camlprog.exe
foo
bar
To me, the first case is definitely wrong: camlprog is being passed foo bar as its only argument instead of two separate foo and bar arguments. I imagined it would be equivalent to:
c:\> c:\cygwin\bin\bash
jonathan@host:$ c:/.../camlprog "foo" bar
which of course prints
foo
bar
Am I missing something? Does anyone have an idea what’s going on?
Thanks,
jonathan
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:
And invoke it passing your parameter:
As result you will get:
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:
Using single quotes first and double quotes later, the script
camlprogseems to run as expected.