Search notes:

cmd.exe - shift

simple example

setlocal enableExtensions

@echo param 1 = %1
@echo param 2 = %2
@echo param 3 = %3

@echo now shifting parameters by one
@shift

@echo param 1 = %1
@echo param 2 = %2
@echo param 3 = %3

@echo now shifting parameters by one
@shift

@echo param 1 = %1
@echo param 2 = %2
@echo param 3 = %3
Github repository about-cmd.exe, path: /commands/shift/shiftParams.bat
When called like so…
C:\> shiftParams one two three four five six seven eight nine
… this batch file prints
param 1 = one
param 2 = two
param 3 = three
now shifting parameters by one
param 1 = two
param 2 = three
param 3 = four
now shifting parameters by one
param 1 = three
param 2 = four
param 3 = five

shift and %*

%* is not affected by a shift.
@echo off

echo %%* = %*
echo %%1 = %1

echo Shifting...

echo %%* = %*
echo %%1 = %1
Github repository about-cmd.exe, path: /commands/shift/shift-star.bat
If this script is invoked like so …
C:\> shift-star.bat one two three
… it prints
%* = one two three
%1 = one
Shifting...
%* = one two three
%1 = one

Using shift within parentheses

The effect of shift within parentheses is delayed to «outside» the parentheses. This can be demonstrated with the following batch file:
@echo off
setlocal

@if [%1] == [-x] (
   shift
   echo %%1=%1
   set inside=%1
)

set  outside=%1

echo inside=%inside%
echo outside=%outside%
Github repository about-cmd.exe, path: /commands/shift/paranthesis.bat
If executed with the parameters -x foo, it assigns -x to %inside% (because the effect of shift is not immediate), but assigns foo to %outside% (because the effect has now taken place):
C:\> paranthesis.bat -x foo
%1=-x
inside=-x
outside=foo

shift /n n

The documentation says that, with enabled command extesions, the shift command can be given a number of positions to shift, for example shift /N 3.
However, I could not confirm that and received a Invalid parameter to SHIFT command error message.

See also

The batch file arguments (%1, %2 …, %* and %0)
shift is affected by whether command extensions are enabled or disabled.
cmd.exe: Built-in commands

Index