How can I stop percentage expansion in a batch file?
(This is on NT based Windows like 2000, XP, Vista, 7)
On the command-line, the percentage characters are ignored:
wget "http://www.justitie.nl/images/Handleiding%20voor%20verwerkers%20persoonsgegevens_tcm34-3940.pdf"
So it correctly downloads this file (each %20 becomes a space):
"http://www.justitie.nl/images/Handleiding voor verwerkers persoonsgegevens_tcm34-3940.pdf"
But inside a batchfile, all the %20 are being interpreted as expanding parameter 2 (which is empty) resulting in this file to get downloaded (each %20 becomes 0):
"http://www.justitie.nl/images/Handleiding0voor0verwerkers0persoonsgegevens_tcm34-3940.pdf"
Is there a way to circumvent the percentage parameter expansion?
--jeroen
Solution 1:
Double the percent sign:
wget "http://www.justitie.nl/images/Handleiding%%20voor%%20verwerkers%%20persoonsgegevens_tcm34-3940.pdf"
Solution 2:
%
is used for variables in Windows' cmd.exe (and its predecessor command.com
).
The escape character in cmd.exe is ^
:
> echo foo^%bar foo%bar