3

Batch files - Support of syntax with ending percent sign to access arguments

I noticed on a Windows XP system that in batch files the command-line arguments can be accessed even using a %\d% syntax.

You can verify it for example with this:

@echo off

echo %%1:"%1"
echo %%1%%:"%1%"

if %1==%1% (
  echo yes, %%1==%%1%%
)

I wasn't able to find any reference to this thing, the documentation I saw only mentions the %\d syntax.

I'd like to know if it is an official feature (at least on some versions of the command line), an undocumented one or an accidental bug and on which versions of DOS and Windows it works.


EDIT:

I thought that what's happening might also be the result of the interpreter simply ignoring the percent sign, as it does in echo messages.

I don't know if there's a way to verify this hypothesis.

gbr
  • 1,264
  • 8
  • 27

1 Answers1

3

A single percent sign in a line will be removed, that's all.
See also cmd.exe parser rules

Community
  • 1
  • 1
jeb
  • 78,592
  • 17
  • 171
  • 225
  • 1
    That question thread is incredible, thanks! I think this case is not covered by the answer you linked though, just by the following [community wiki](https://stackoverflow.com/a/7970912/2130006) (point 1.4) – gbr Jun 29 '16 at 13:58