Purpose:Allows the use of more than 10 parameters in a batch file, or iterating through its parameters


Format:SHIFT [[-]n | /n]


nNumber of positions to shift (an unsigned number), or the position of the parameter to be deleted.




SHIFT is provided for compatibility with batch files written for CMD, where it was used to access more than the CMD limit of 10 parameters. TCC supports 8191 parameters (%0 to %8190), so you  do not need to use SHIFT for batch files running exclusively under TCC.


SHIFT n moves each of the batch file parameters n positions to the left. The default value for n is 1. For example, SHIFT (with no parameters) makes the parameter %1 become to %0, the parameter %2 becomes %1, etc.


SHIFT -n moves parameters to the right, but it is limited to moving them back to their position on entry to the batch file.


This form of SHIFT also affects the special parameters %n$, %$ and %# (number of command parameters). However, for compatibility with CMD, this form of the SHIFT command does not alter the contents or order of the parameters returned by %*. See Batch File Parameters for details.


For example, create a batch file called TEST.BAT:


echo %1 %2 %3 %4


echo %1 %2 %3 %4

shift 2

echo %1 %2 %3 %4

shift -1

echo %1 %2 %3 %4


Executing the command below produces the following results:


[c:\] test one two three four five six seven

one two three four

two three four five

four five six seven

three four five six



SHIFT /n This form of the command irreversibly deletes parameter %n from the command tail, and shifts all parameters originally to its right 1 position to the left. For example,


shift /2


leaves parameters %0 and %1 unchanged, and moves the value of %3 to position %2, %4 to %3, etc.


This form of SHIFT also affects the special parameters %n$, %$ and %# (number of batch file parameters), and unlike the first form, it also affects %*. See Batch File Parameters for details.