Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does %* mean in a batch file?

I have seen the usage of %* in batch files and command lines.

Can someone explain the typical usage of %* with an example?

like image 693
feminkk Avatar asked Apr 22 '13 10:04

feminkk


People also ask

What does %% A mean in batch file?

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

What does %~ mean in batch?

The tilde (~) sign is used in different ways in batch files: Argument quote removal. A tilde sign before an command-line argument (such as "%~1") indicates to remove the surrounding quotes from the parameter. Such if the value for %1 is "Hi" then %~1 will expand to only Hi.

What does the symbol do in batch files?

The @ symbol tells the command processor to be less verbose; to only show the output of the command without showing it being executed or any prompts associated with the execution. When used it is prepended to the beginning of the command, it is not necessary to leave a space between the "@" and the command.

What is %% f in batch script?

%f is a "for-variable" or "loop-variable" (I also heard the term "Metavariable"). It's valid only within the for loop and has no meaning after the for loop ends. Environment variables are manipulated with the set command (see set /? ), for for-variables, there are "modifiers" (see for /? ) – Stephan.


4 Answers

It means "all the parameters in the command line".

For example, it's useful when you want to forward the command line from your batch file to another program:

REM mybatchfile.cmd
echo You called this with arguments: %*
echo I will now forward these to the DIR command.
dir %*
like image 103
Jon Avatar answered Nov 02 '22 11:11

Jon


One important point not listed in any of the previous answers: %* expands to all parameters from the command line, even after a SHIFT operation.

Normally a SHIFT will move parameter %2 to %1, %3 to %2, etc., and %1 is no longer available. But %* ignores any SHIFT, so the complete parameter list is always available. This can be both a blessing and a curse.

like image 29
dbenham Avatar answered Nov 02 '22 10:11

dbenham


%* expands to the complete list of arguments passed to the script.

You typically use it when you want to call some other program or script and pass the same arguments that were passed to your script.

like image 37
David Heffernan Avatar answered Nov 02 '22 10:11

David Heffernan


The %* modifier is a unique modifier that represents all arguments passed in a batch file. You cannot use this modifier in combination with the %~ modifier. The %~ syntax must be terminated by a valid argument value.

Source:

  • "Using batch parameters" on Microsoft.com (defunct)
  • "Using batch parameters" (Archive.org mirror)
like image 33
Michael Krupp Avatar answered Nov 02 '22 09:11

Michael Krupp