A common practice in batch files is invoking another batch file or program with the arguments that was given to batch files.

Invoking with all arguments

It is straight forward task since %* holds all the arguments the was given to a batch files (%1,%2,%3 and does not includes %0 - the batch file name)

@echo off
echo %*
C:\>a1.bat arg1 arg2 arg3 "arg4 with space"
arg1 arg2 arg3 "arg4 with space"

Invoking with all arguments from specific position

Sometimes you may want to use the first arguments that was given to the batch file and move the rest of them to another batch file or program.

shift command

It may seem that shift is the right answer. shift changes the position of batch parameters in a batch file . Unfortunately, shift only changes the values of the batch parameters %0 through %9 by copying each parameter into the previous one (%1 is copied to %0, %2 is copied to %1, and so on). It does not change the value of %* as the following script demonstrate:

@echo off
echo In start of script
echo     %%0,%%1,%%2,%%3,%%4,%%5 : %0,%1,%2,%3,%4,%5
echo     %%*                = %*
shift
shift
echo After 2 shifts
echo     %%0,%%1,%%2,%%3,%%4,%%5 : %0,%1,%2,%3,%4,%5
echo     %%*                = %*
C:\>a2.bat arg1 arg2 arg3 arg4 arg5
In start of script
    %0,%1,%2,%3,%4,%5 : C:\a2.bat,arg1,arg2,arg3,arg4,arg5
    %*                = arg1 arg2 arg3 arg4 arg5
After 2 shifts
    %0,%1,%2,%3,%4,%5 : arg2,arg3,arg4,arg5,,
    %*                = arg1 arg2 arg3 arg4 arg5

using shift to the task

The following script define build_args which take a position and list of arguments. The function will set the args variable list of arguments from position.

@echo off
call :build_args 2 %*
echo args from position 2 : %args%
call :build_args 3 %*
echo args from position 3 : %args%
call :build_args 4 %*
echo args from position 4 : %args%
goto :eof
:build_args
  set first=%1
  For /L %%k in (1,1,%first%) Do shift
  set args=%1
  :loop
    shift
    if [%1] == [] goto :eof
    set args=%args% %1
    goto :loop
  goto :eof
C:\>a3.bat 1 2 3 4 5
args from position 2 : 2 3 4 5
args from position 3 : 3 4 5
args from position 4 : 4 5