Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
buildconf.bat: Fix echo for paths with special chars #379
Just noticed that the quotes do not get stripped before printing, so we get output that looks like:
If anyone knows how to solve this, please let me know. The hacks that I found on StackOverflow made my brain hurt. Otherwise, I think it's better to have some quotes in the output than to have a broken build ;)
Thanks for the report and attempted fix.
The problem isn't the echo as such - it will work under certain circumstances such as in a brand new batch file with nothing else in it.
The problem is the if statement as it uses brackets - although I'm not too sure why.
Moving the echo outside the if or into a separate function call fixes the problem.
+1 on the patch. It's the right parenthesis. The command interpreter expands the variables before it evaluates the if block. It's easier to understand if you boil the other stuff away
The interpreter expands all variables first (think preprocessor):
It starts to interpret it as an if statement:
but then chokes because the leftover isn't expected:
I think the best way is to wrap it in quotes, that is what I do in many of my scripts because it is the most resilient. You may see some people use delayed variable expansion, ie
If you really don't want quotes enable delayed expansion temporarily since nested setlocal is allowed:
Of course if that block were more complicated and included variables expanded normally that contained exclamation points, their data would be corrupted (assuming you didn't do it purposely).
added a commit
this pull request
Aug 14, 2015
I've pushed a fix that simply moves the echo outside of the if statement.
I don't want to enable delayed variable expansion as that relies on Windows NT and would break on legacy systems and like the author I don't like the use of quotes as they get output rather than stripped off.
An alternative fix is to move the echo and copy into it's own function and have the if call that function.