Subscribe to Windows IT Pro
December 23, 2002 12:00 AM

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

Windows IT Pro
InstantDoc ID #37486
Rating: (6)

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.

Related Content:

ARTICLE TOOLS

Comments
  • warwick
    8 years ago
    Mar 12, 2004

    This works fine for me in windows 2000, %% is translated to % when the batch file runs.

  • Jason Stracner
    9 years ago
    Apr 22, 2003

    This didn't work for me. I am using a windows 2000 os. Is that a problem?

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.