Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are "%1" and "%2" in batch files?

What does the following %1 means (in a .bat file)?

jsmin <%1 >%2 
like image 252
Ricky Avatar asked Feb 22 '10 09:02

Ricky


People also ask

What is %1 in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.

What does %% mean in batch script?

Represents a replaceable parameter. Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> )

What is %% g'in batch file?

%%parameter : A replaceable parameter: in a batch file use %%G (on the command line %G) FOR /F processing of a command consists of reading the output from the command one line at a time and then breaking the line up into individual items of data or 'tokens'.

What does 0 |% 0 Do in batch?

What it is: %0|%0 is a fork bomb. It will spawn another process using a pipe | which runs a copy of the same program asynchronously. This hogs the CPU and memory, slowing down the system to a near-halt (or even crash the system).


1 Answers

It represents the first command line argument passed to the batch file.

If you run your batch file with:

myfile.bat firstArg secondArg 

%1 becomes "firstArg" and %2 becomes "secondArg"

The related shift command shifts the position of arguments one to the left. Running shift once in a batch file will make "%1" value to be the second argument, "%2" becomes the third, and so on. It's useful for processing command line arguments in a loop in the batch file.

like image 106
mmx Avatar answered Oct 13 '22 00:10

mmx