What does %* mean in a batch file?

前端 未结 4 1222
南方客
南方客 2021-02-02 08:14

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

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

相关标签:
4条回答
  • 2021-02-02 08:57

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

    0 讨论(0)
  • 2021-02-02 08:57

    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)
    0 讨论(0)
  • 2021-02-02 09:01

    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.

    0 讨论(0)
  • 2021-02-02 09:14

    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 %*
    
    0 讨论(0)
提交回复
热议问题