windowsbatch-file

How to get list of arguments?


I'd like to find a Windows batch counterpart to Bash's $@ that holds a list of all arguments passed into a script.

Or I have to bother with shift?


Solution

  • dancavallaro has it right, %* for all command line parameters (excluding the script name itself). You might also find these useful:

    %0 - the command used to call the batch file (could be foo, ..\foo, c:\bats\foo.bat, etc.)
    %1 is the first command line parameter,
    %2 is the second command line parameter,
    and so on till %9.

    SHIFT can be used for parameter after 9th, but it doesn't affect %* and there's no concept like SHIFT [/n] for accessing entire command line starting from n-th parameter.

    %~nx0 - the actual name of the batch file, regardless of calling method (some-batch.bat)
    %~dp0 - drive and path to the script, including trailing slash (d:\scripts\)
    %~dpnx0 - is the fully qualified path name of the script (d:\scripts\some-batch.bat)

    More info and examples at https://www.ss64.com/nt/syntax-args.html and https://www.robvanderwoude.com/parameters.html