how to get batch file parameters from Nth position on?

batch-file, windows

Solution

Here's how you can do it without using `SHIFT`:

@echo off

for /f "tokens=1-3*" %%a in ("%*") do (
    set par1=%%a
    set par2=%%b
    set par3=%%c
    set therest=%%d
)

echo the script is %0
echo Parameter 1 is %par1%
echo Parameter 2 is %par2%
echo Parameter 3 is %par3%
echo and the rest are %therest%

Problem

Further to How to Pass Command Line Parameters in batch file how does one get the rest of the parameters with specifying them exactly? I don't want to use SHIFT because I don't know how many parameters there might be and would like to avoid counting them, if I can. For example, given this batch file: ``` @echo off set par1=%1 set par2=%2 set par3=%3 set therest=%??? echo the script is %0 echo Parameter 1 is %par1% echo Parameter 2 is %par2% echo Parameter 3 is %par3% echo and the rest are %therest% ``` Running `mybatch opt1 opt2 opt3 opt4 opt5 ...opt20` would yield: ``` the script is mybatch Parameter 1 is opt1 Parameter 2 is opt2 Parameter 3 is opt3 and the rest are opt4 opt5 ...opt20 ``` I know `%*` gives all the parameters, but I don't wan't the first three (for example).

Original source

Related problems