What is the difference between % % and ! ! in a batch file?

1.5k Views Asked by At

What is the difference between these 2 pieces of code in a batch file?

set str=!str:%%20= !

and

set str=%str:%%20= %
1

There are 1 best solutions below

1
Sam On

Finally, after hours I could find the explanation. According to this page How-to: Escape Characters, Delimiters and Quotes at the Windows command line in the paragraph "Escaping Percents" :

Escaping Exclamation marks When the shell is running in EnableDelayedExpansion mode the ! character is used to denote a variable and so must be escaped (twice) if you wish to treat it as a regular character:

^^!