Hi, Short summary: getting nested quotes in an argument through to a Cygwin process from DOS is problematic, and there does not seem to be any detailed spec for how to escape quotes correctly. Backslash characters seem to be spuriously generated.
I'm working on a build system (GNU make, Windows build), which invokes the Cygwin shell to run commands, like so: sh.exe -c "command arg1 arg2 etc" I've run into some serious problems when command is a DOS path (e.g. c:/qtpath/moc.exe) and one of the arg's is quoted. Naturally, the problem could be at two points: 1) the Windows code in make could be escaping things incorrectly for the Cygwin loader to interpret 2) the Cygwin loader does not handle this case correctly. ************ A simple test ************** I made the following simple Cygwin program, to better show what sh.exe would be getting from make: #include <stdio.h> int main(int argc, char **argv) { int i; for (i = 1; i < argc; i++) printf("%d : %s\n", i, argv[i]); return 0; } ------ Normal program name ------ c:\cygwin\home\akhripin>args "foo 1 ""2 3"" 4" 1 : foo 1 "2 3" 4 ------ DOS'y program name ------ c:\cygwin\home\akhripin>args "c:/foo 1 ""2 3"" 4" 1 : c:/foo 1 \2 3\ 4 As you can see, the second case causes \ escape characters to show up - and the worst thing, one of them is now escaping a space - so the above would be further split up as c:/foo 1 2 "3 4" -- completely changing which arguments were grouped together. ************ The noglob option ************** When I turn on CYGWIN=noglob, there seems to be no way at all to get a double quote through to the test program - no amount of escaping or single quotes does the trick. As such, that does not seem to be an option available to me. ************ Is the above a bug? ************** I cannot find any mailing list entries or documentation on how quotes are processed. I looked at the cygwin source (winsup/sources/dcrt0.cc) and it looks like it enables special processing when an argument starts with Letter-Colon. I'm sure that's there for good reasons - but is that processing correct for cases with quotes? Basically, my question boils down to: is this a Cygwin problem that can be fixed, or should I pursue a fix to Windows make? ************ Correct escaping ************** From what I've been able to determine, there is no consistent way to escape " and \ characters that works both for arguments that are "normal" and those that look like DOS paths. If that is the intent, that's fine - I've been working on a patch for make. My conclusion is that for escaping normal arguments, the current approach of turning nested " into "" and \ into \\ works fine. For arguments that look like DOS paths, it looks like the right answer is pretty complex: enclose the whole argument in " if it is not, then use "'"'" for " and "\" for \; what this does is close the current double quoted statement, insert the desired character, and resume the double quoted statement -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple