Percent Signs Stripped from Batch File Text
This article was previously published under Q75634
This article has been archived. It is offered "as is" and will no longer be updated.
Using a percent sign (%) in a batch file requires that two percentsigns (%%) be specified.
For example, the command to display "5%" from a batch file would be :
MS-DOS uses %1, %2, ... %9 as replaceable command line parameters. Forexample, before executing the command ECHO %1, %1 will be replacedwith the first parameter passed to the batch file. %0 is replaced withthe command used to execute the batch file.
A single percent sign on a line is treated as a "nul" character in abatch file. For example:
ECHO % is processed as ECHO ECHO a%b is processed as ECHO abIf a command contains two percent signs, MS-DOS will treat any charactersbetween them as an environment variable to be expanded. For example, if theSET command shows that the current environment variables are
COMSPEC=C:\COMMAND.COM PATH=C:\DOS PROMPT=$P$G B=Cthen
ECHO %PATH% is processed as ECHO C:\DOS ECHO a%b% is processed as ECHO aC ECHO a%b b%a is processed as ECHO aaIf there are no characters between the two percent signs, one percentsign is stripped off and the other will remain. This is why a FOR commandthat echos the name of each file with a .COM extension would be
FOR %V IN (*.COM) DO ECHO %Vbut if the same command is placed in a batch file, the following isrequired:
FOR %%V IN (*.COM) DO ECHO %%VReference(s):
"Microsoft MS-DOS Batch File Quick Reference," Microsoft Press.
6.22 3.20 3.21 3.30 3.30a 4.00 4.01 4.01a 5.00 5.00a 6.00 6.20
Article ID: 75634 - Last Review: 12/04/2015 09:09:40 - Revision: 2.0
Microsoft MS-DOS 3.1, Microsoft MS-DOS 3.2 Standard Edition, Microsoft MS-DOS 3.21 Standard Edition, Microsoft MS-DOS 3.3 Standard Edition, Microsoft MS-DOS 3.3a, Microsoft MS-DOS 4.0 Standard Edition, Microsoft MS-DOS 4.01 Standard Edition, Microsoft MS-DOS 5.0 Standard Edition, Microsoft MS-DOS 5.0a, Microsoft MS-DOS 6.0 Standard Edition, Microsoft MS-DOS 6.2 Standard Edition, Microsoft MS-DOS 6.21 Standard Edition, Microsoft MS-DOS 6.22 Standard Edition
- kbnosurvey kbarchive KB75634