SHIFT

Changes the position of replaceable parameters in a batch file.

SHIFT [/n]

Where:

  • /n - Specifies a number between 0 and 8 (e.g. /3). It means that it changes the position from one number to another (e.g. with 3: SHIFT /3 changes %4 to %3, from %5 to %4, from %6 to %5 etc… and leaving %0, %1 and %2 unchanged). By default, n is set to 0.

Examples:

1. Change the position of replaceable parameters of %3 to %2, %4 to %3 etc… leaving %0 and %1 unchanged:

shift /2

 

2. Delete all files specified as arguments by calling the following batch file from the command line (see IFIF, GOTOGOTO and DELDEL):

:next
if "%1"=="" goto :eof
del %1
shift
goto next

 

Further information:

When calling a batch file from the command line, you can specify additional arguments after the file name. These arguments can then be accessed using the syntax %0, %1, %2 etc... For example, calling the following command:

mylittleprogram.bat timmy tommy jimmy

Within the invoked script, the %0 parameter will be assigned mylittleprogram.bat, %1 will be assigned timmy, %2 will be assigned tommy and %3 will be assigned jimmy. The subsequent parameters (%4, %5, etc…) will be given an empty string.

Comments