How can I use the percent symbol (%) in a batch file?

A. Although you can use the % symbol to specify a variable in a batch file, you must type in two % symbols in succession. For example, you must type

for /L %%n IN (1,1,10) DO @ECHO %%n
to tell the batch file to interpret the command as
for /L %n IN (1 1 10) DO @ECHO %n

If you simply want to output the % symbol from a batch file, you must also type in two % symbols in succession. For example, type

echo 10%%
to display
10%

The standard % symbols that surround an environment variable remain the same, regardless of whether you're typing them at a command prompt or including them in a batch file. For example, type

echo %date%
to display the date.
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish