What does %* mean in a batch file

2019-03-23 19:07发布

问题:

I have seen the usage of %* in batch files and command lines. Googling did not give me any results. Can some one explain the typical usage of %* with an example.Thanks

回答1:

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


回答2:

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.



回答3:

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



回答4:

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

See:

  • microsoft.com (defunct)
  • archive.org