Blog on software engineering
How to use special characters in echo, by escaping characters

How to use special characters in echo, by escaping characters

If you want to use special characters in your echo statement, use the ^ character before the special character. If you want to escape the % character in an echo statement double the % like:

Script Test.bat
echo %%1
Usage
C:\Test.bat “C:\Program Files”
Result
“C:\Program Files”

Escape character (http://www.ss64.com/nt/setlocal.html)
Adding the escape character before a command symbol     allows it to be treated as ordinary text.
When piping or redirecting any of these charcters you should
prefix with the escape character: \ & | > < ^
e.g.  ^\  ^&  ^|  ^>  ^<  ^^

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.