I have seen the usage of %*
in batch files and command lines.
Can someone explain the typical usage of %*
with an example?
%*
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.
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:
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.
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 %*