59

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

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

2
  • 1
    Does this answer your question? What does %* mean?
    – phuclv
    Aug 20, 2021 at 3:53
  • @phuclv I really think the duplicate target direction should be reversed. This question seems like a better canonical than the one you linked to.
    – cigien
    Aug 20, 2021 at 23:04

5 Answers 5

67

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

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.

13

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

5

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:

1
  • I added a link to the an archived version of the page. Please note that the documentation refers to Windows XP though. There might be different modifiers available for Windows 10 Jul 5, 2018 at 7:58
2

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 & ( ) [ ] { } ^ = ; ! ' + , ` ~

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.