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

John Savill

December 22, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like