Escape Characters in DOS Batch File (.bat file)


DOS Command does interpret some special characters before executing a command, such as percent sign ( % ), and the redirection symbols ( < | > ).

Windows 95/98/NT/2000/XP/2003/2008/7/etc. and OS/2 systems, also interpret double quotes ( " ) and ampersands ( & ), as revealed within the Conditional Execution page.

In batch files (.bat files), the percent sign (%) should be replaced by a double percent sign ( %% ). However, when you run a command line in DOS Window or CMD Window directly, you should use a single percent sign, for example,

for %F in (D:\temp\*.pdf) do echo "%F" "%~nF.pdf"

If you put above command line into a .bat file, you should change it to following,

for %%F in (D:\temp\*.pdf) do echo "%%F" "%%~nF.pdf"

In Windows 95/98/NT/2000/XP/2003/2008/7/etc., and OS/2 systems, the redirection symbols may be used by putting them between double quotes ( ">" ). Even so, the quotes can be passed to the command line as well, this behaviour is not like the double percent sign (%%).

Windows and OS/2 Systems are allow using carets ( ^ ) to escape some special characters. Even linefeeds may be escaped this way, as is shown in the Useless Tips page.

If you intend to "nest" commands with escaped characters, you may need to escape the escape character itself too, this will make it difficulty to read or debug your batch files.


VN:F [1.9.20_1166]
Rating: 8.0/10 (3 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)
Escape Characters in DOS Batch File (.bat file), 8.0 out of 10 based on 3 ratings

Random Posts

Leave a Reply

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

Verify Code   If you cannot see the CheckCode image,please refresh the page again!