I just need to ask if this is expected behaviour, it sure surprised me.
We have a batch file that copies some files from a sub-directory of where it is located, to another location on every developers machine. Since for some developers, this target directory differs from the rest, we've set a user environment variable, and used that in the batch file.
This is a sample line from the batch file:
ROBOCOPY Staging\*.* "%DISTRIBUTE_TARGET%" *.* /IS
This failed on one machine, and after some experimentation, it dawned on me that on this machine, the variable had a trailing backslash as part of the variable content.
On most machines (in fact, all the other machines, where it worked), the variable looked like this:
DISTRIBUTE_TARGET=C:\Some\Directory
but on this machine, it was:
DISTRIBUTE_TARGET=C:\Some\Directory\
notice the added backslash there.
The error message given by ROBOCOPY was that there was something wrong with the second parameter, but it seemed to think that everything from the start of that variable, and to the end of the line, was all in the 2nd parameter.
Ie. the error message looked like this:
Error in second parameter: "C:\Some\Directory\" *.* /IS"
What I assume happened is that the backslash "escaped" the quote character, which removed its meaning as "end of quoted parameter", and thus the rest of the line was just grabbed as part of the argument.
Is this expected behavior? Does this mean that variables with a trailing backslash, for whatever reason or purpose, just cannot be safely used?
