Percent Signs Stripped from Batch File Text

Article translations Article translations
Article ID: 75634 - View products that this article applies to.
This article was previously published under Q75634
Expand all | Collapse all


Using a percent sign (%) in a batch file requires that two percent signs (%%) be specified.

For example, the command to display "5%" from a batch file would be :
   ECHO 5%%


MS-DOS uses %1, %2, ... %9 as replaceable command line parameters. For example, before executing the command ECHO %1, %1 will be replaced with the first parameter passed to the batch file. %0 is replaced with the command used to execute the batch file.

A single percent sign on a line is treated as a "nul" character in a batch file. For example:
   ECHO %     is processed as ECHO
   ECHO a%b   is processed as ECHO ab
If a command contains two percent signs, MS-DOS will treat any characters between them as an environment variable to be expanded. For example, if the SET command shows that the current environment variables are
   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 aa
If there are no characters between the two percent signs, one percent sign is stripped off and the other will remain. This is why a FOR command that echos the name of each file with a .COM extension would be
but if the same command is placed in a batch file, the following is required:
   FOR %%V IN (*.COM) DO ECHO %%V

"Microsoft MS-DOS Batch File Quick Reference," Microsoft Press.


Article ID: 75634 - Last Review: May 10, 2003 - 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
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from