Reputation: 6607
The output of this batch script is Hello!
as expected:
@echo off
echo Hello!
However, with Delayed Expansion enabled the output is now Hello
:
@echo off
setlocal EnableDelayedExpansion
echo Hello!
A trick is to insert endlocal
just before the echo
:
@echo off
setlocal EnableDelayedExpansion
...
endlocal
echo Hello!
setlocal EnableDelayedExpansion
This is tedious, however. According to this Microsoft reference, some charaters like percent (%) and caret (^) can be used to escape (and therefore print) characters such as %
, |
and >
.
Is there any escape character for the exclamation mark (!) without resorting to the endlocal
trick?
Upvotes: 1
Views: 1058
Reputation: 2951
one can take @npocmaka's answer a step further, so that exclamation marks can be dispalyed without expanding in later use.
@Echo Off & setlocal DisableDelayedExpansion
Set "/Ex=^^!"
Setlocal EnableDelayedExpansion
Echo(%/Ex%test%/Ex%
Upvotes: 0
Reputation: 57252
try with double caret:
@echo off
setlocal enableDelayedExpansion
echo ^^!
Upvotes: 3