Command: shift

  SHIFT changes the position of replacable parameters
  in a batch file.
  (Used to shift the replacable batch file parameters).
  SHIFT is a BATCH-FILE / AUTOEXEC.BAT / FDAUTO.BAT command.

Syntax:

  SHIFT
  SHIFT [DOWN]

Options:

  Shifts the arguments of a batch script one position up (first variant)
  or down (second variant).

Comments:

  Within a batch script the automatic variables %0 through %9 are
  replaced by the script name and the first nine arguments. This can be
  imagined as a window to ten arguments of the script. SHIFT will allow
  to move this window of ten arguments towards its end (up) or its start
  (down).
  After SHIFT has been executed, the former %0 is hidden and in-
  accessable, %1 became %0, %2 became %1 a.s.o, %9 became %8 and the
  formerly hidden tenth argument became %9. SHIFT DOWN reverses one
  SHIFT command.
  SHIFT can be called as many times as wanted, SHIFT DOWN won't allow to
  underflow the very first argument.
  SHIFT is a command internal to command.com and needs no other file
  in order to work.

Examples:

  Example 1:
  If the batch script B.BAT:
    @ECHO OFF
    ECHO 0: %0
    ECHO 1: %1
    ECHO 2: %2
    had been executed using:
    B.BAT 1 2 3 4
    it displays:

    B.BAT
    1
    2

  If a SHIFT command had been inserted as second line, the same
  call displays:

    1
    2
    3

  Example 2:
  Script test.bat, execute it with: "test 0 1 2 3 4 5 6 7 8 9"
    :START
    cls
    @echo off
    SHIFT
    if %0X==X goto :END
    md folder%0
    echo The actual shift parameter is: %0
    echo Folder%0 was created.
    echo The numbers go upwards!
    pause
    goto :START
    :END
    cls
    echo The shift job (creating folders) is done...
    pause
    cls
    choice /C:YN "Do you want to delete this folders again? "

    if errorlevel 2 goto :FINISH
    if errorlevel 1 goto :DELETE

    :DELETE
    cls
    SHIFT DOWN
    if %0X==X goto :END1
    REM The following two lines are needed as SHIFT shows the name of
    REM the batch file (test or test.bat)!
    if %0X==testX goto :END1
    if %0X==test.batX goto :END1
    rd folder%0
    echo The actual shift parameter is: %0
    echo Folder%0 was deleted.
    echo The numbers go downwards!
    pause
    goto :DELETE

    :END1
    cls
    echo The shift down job (deleting folders) is done...
    pause
    cls
    goto :FINISH

    :FINISH
    @echo on
    cls

See also:

  @(at)
  autoexec.bat/fdauto.bat
  choice
  command.com/freecom
  errorlevel
  batch files
  echo
  if

  Copyright © 2003 Robert Platt, updated 2007 and 2022 by W. Spiegl.

  This file is derived from the FreeDOS Spec Command HOWTO.
  See the file H2Cpying for copying conditions.