shift


shift

  • help shift

Output:

Changes the position of replaceable parameters in a batch file.

SHIFT [/n]

If Command Extensions are enabled the SHIFT command supports
the /n switch which tells the command to start shifting at the
nth argument, where n may be between zero and eight.  For example:

    SHIFT /2

would shift %3 to %2, %4 to %3, etc. and leave %0 and %1 unaffected.

Return Code: 1


example

_shift1.bat

call :test1 a b c d e f g h i j k l m n o p q r
call :test2 a b c d e f g h i j k l m n o p q r
call :test3 a b c d e f g h i j k l m n o p q r
shift /9

@goto:eof

:test1
@echo Before SHIFT *2 %%0=%0 %%1=%1 %%2=%2 %%3=%3 %%4=%4 %%5=%5 %%6=%6 %%7=%7 %%8=%8 %%9=%9 %%*=%*
@shift
@shift
@echo After  SHIFT *2 %%0=%0 %%1=%1 %%2=%2 %%3=%3 %%4=%4 %%5=%5 %%6=%6 %%7=%7 %%8=%8 %%9=%9 %%*=%*
@goto:eof

:test2
@echo Before SHIFT /3 %%0=%0 %%1=%1 %%2=%2 %%3=%3 %%4=%4 %%5=%5 %%6=%6 %%7=%7 %%8=%8 %%9=%9 %%*=%*
@shift /3
@echo After  SHIFT /3 %%0=%0 %%1=%1 %%2=%2 %%3=%3 %%4=%4 %%5=%5 %%6=%6 %%7=%7 %%8=%8 %%9=%9 %%*=%*
@goto:eof

:test3
@echo Before SHIFT *9 %%0=%0 %%1=%1 %%2=%2 %%3=%3 %%4=%4 %%5=%5 %%6=%6 %%7=%7 %%8=%8 %%9=%9 %%*=%*
@for /L %%n in (1,1,9) do @shift
@echo After  SHIFT *9 %%0=%0 %%1=%1 %%2=%2 %%3=%3 %%4=%4 %%5=%5 %%6=%6 %%7=%7 %%8=%8 %%9=%9 %%*=%*
@goto:eof


c:\example>call :test1 a b c d e f g h i j k l m n o p q r
Before SHIFT *2 %0=:test1 %1=a %2=b %3=c %4=d %5=e %6=f %7=g %8=h %9=i %*=a b c d e f g h i j k l m n o p q r
After  SHIFT *2 %0=b %1=c %2=d %3=e %4=f %5=g %6=h %7=i %8=j %9=k %*=a b c d e f g h i j k l m n o p q r

c:\example>call :test2 a b c d e f g h i j k l m n o p q r
Before SHIFT /3 %0=:test2 %1=a %2=b %3=c %4=d %5=e %6=f %7=g %8=h %9=i %*=a b c d e f g h i j k l m n o p q r
After  SHIFT /3 %0=:test2 %1=a %2=b %3=d %4=e %5=f %6=g %7=h %8=i %9=j %*=a b c d e f g h i j k l m n o p q r

c:\example>call :test3 a b c d e f g h i j k l m n o p q r
Before SHIFT *9 %0=:test3 %1=a %2=b %3=c %4=d %5=e %6=f %7=g %8=h %9=i %*=a b c d e f g h i j k l m n o p q r
After  SHIFT *9 %0=i %1=j %2=k %3=l %4=m %5=n %6=o %7=p %8=q %9=r %*=a b c d e f g h i j k l m n o p q r

c:\example>shift /9
Invalid parameter to SHIFT command

Last updated on Oct 01, 2022 08:52 UTC
Built with Hugo
Theme Stack designed by Jimmy