Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does %%a mean? (Batch)

What does the %%a mean?
I understand the context but not how to use it. For example :

FOR %%a in (%HELP%) DO echo I don't Know what it means
like image 635
Moonicorn Avatar asked Feb 24 '15 06:02

Moonicorn


People also ask

What does %% A mean in batch?

%%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.

Why is %% used in batch file?

%% in batch acted like \\ in bash. Where one would need to cancel the meaning of the previous percent-sign in a batch file; because variables in batch look like %var% . So because percent had a special meaning you needed to use %%var%% so a variable was still usable in a batch file.

What is %% f in batch script?

By default, /F breaks up the command output at each blank space, and any blank lines are skipped.

What is %% K in batch file?

So %%k refers to the value of the 3rd token, which is what is returned.


1 Answers

%%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 %%a in (A B C D E) do Echo %%a

Produces

A
B
C
D
E

Example 2:

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
like image 76
Monacraft Avatar answered Oct 11 '22 15:10

Monacraft