Reputation: 1225
I have seen the usage of %*
in batch files and command lines.
Can someone explain the typical usage of %*
with an example?
Upvotes: 67
Views: 72369
Reputation: 21
It is also important to note that %*
does not go through the parsing that the individual %n
arguments do. For example, if the parameters are:
a "b c" j=k d,e,f
Then ECHO %*
will display:
a "b c" j=k d,e,f
But ECHO 1=%1 2=%2 3=%3 4=%4 5=%5 6=%6 7=%7 8=%8 9=%9
will display:
1=A 2="B C" 3=J 4=K 5=D 6=E 7=F 8= 9=
The difference is how parameters which contain special characters, but are NOT enclosed in quotation marks, are handled. The special characters are the usual suspects: space & ( ) [ ] { } ^ = ; ! ' + , ` ~
Upvotes: 2
Reputation: 2120
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:
Upvotes: 5
Reputation: 130879
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.
Upvotes: 36
Reputation: 437544
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 %*
Upvotes: 74
Reputation: 613262
%*
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.
Upvotes: 13