Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 582
gbr Avatar asked Oct 15 '26 04:10

gbr


1 Answers

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

like image 113
jeb Avatar answered Oct 16 '26 19:10

jeb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!