When I type:
set hi=Hello^&World!
echo %hi%
it print Hello and tell me World is not a command
I want it prints Hello&World!
How to do this?
This works for me:
set "hi=Hello^&World!"
echo %hi%
Outputs
Hello&World!
The only secure way to echo the content of a variable is to use the delayed expansion here.
If percent expansion is used, it depends on the content if it fails.
set "var1=Hello ^& World"
set "var2=Hello & World"
setlocal EnableDelayedExpansion
echo !var1!
echo !var2!
echo %var1%
echo %var2% -- fails
The delayed expansion is more usefull as it doesn't interpret any special characters.
More info at SO: How the parser works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With