Escape Characters

Escaping special characters in DOS batch when delayed variable expansion is enabled or disabled.

Description: The command processor handles some characters in a special way and these characters won`t show up in the output as expected when using i.e. the ECHO command. The exclamation mark is handled differently if Delayed Expansion is enabled or disabled.
Script: Download: BatchEscape.bat  
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS

SETLOCAL DISABLEDELAYEDEXPANSION
echo.delayed expansion is DISABLED
echo.1. ^^! :exclamation mark
echo.2. !! :exclamation mark
echo.3. ! :exclamation mark
echo.4. %% :percent
echo.5. ^& :ampersand
echo.6. ^| :vertical line
echo.7. ^^ :caret
echo.

SETLOCAL ENABLEDELAYEDEXPANSION
echo.delayed expansion is ENABLED
echo.1. ^^! :exclamation mark
echo.2. !! :exclamation mark
echo.3. ! :exclamation mark
echo.4. %% :percent
echo.5. ^& :ampersand
echo.6. ^| :vertical line
echo.7. ^^ :caret
echo.
Script Output:
 DOS Script Output
delayed expansion is DISABLED
1. ^! :exclamation mark
2. !! :exclamation mark
3. ! :exclamation mark
4. % :percent
5. & :ampersand
6. | :vertical line
7. ^ :caret

delayed expansion is ENABLED
1. ! :exclamation mark
2. exclamation mark
3. exclamation mark
4. % :percent
5. & :ampersand
6. | :vertical line
7. ^ :caret