I want to make something like this
set ac=&Hello
But it will say 'Hello' is not a command. I tried putting double quote like this,
set ac="&Hello"
But it will show the double quotes. Does anyone have an idea?
I want to make something like this
set ac=&Hello
But it will say 'Hello' is not a command. I tried putting double quote like this,
set ac="&Hello"
But it will show the double quotes. Does anyone have an idea?
Using delayedExpansion
, one can echo
out any content, even special characters without escaping. Take a look at the follow example:
@echo off
setlocal enableDelayedExpansion
set "ac=&Hello"
echo !ac!
This will output &Hello
as you expected. There are still some other methods, but this one is one of the simplest one.
@echo off
setlocal enableDelayedExpansion
set "ac=&Hello"&&echo !ac!
Simillar to the above, this snippet only moves the echo
to the same line as the set
statement. This will be easier to see when echo
ing a large content of text.