总结
%%a
refers to the name of the variable your for loop will write to.
Quoted from for /?
:
FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used. command Specifies the command to carry out for each file. command-parameters Specifies parameters or switches for the specified command. To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I.
Example 1:
for /f "tokens=1,* eol=: delims==" %%A in (%appdata%\gamelauncher\options.txt) do ( if "%%A"=="menu" set usemenu=%%B )
Above snippet would now read the file line by line and for each line would discard everything after a colon (the eol=:
option), use the equals sign as a token delimiter and capture two tokens: The part before the first =
and everything after it.
The tokens are named starting with %%A
so the second one is implicitly(含蓄的) %%B
(again, this is explained in help for
). Now, for each line we examine the first token and look whether it's menu
and if so, assign its value to the usemenu
variable.
Example 2:
for %%a in (A B C D E) do Echo %%a
Produces
A
B
C
D
E
Example 3:
for %%a in (A B C) do (for %%b in (1 2 3) do Echo %%a:%%b)
Produces
A:1
A:2
A:3
B:1
B:2
B:3
C:1
C:2
C:3