Shift

Index

Changes the position of replaceable parameters in a batch program.

Syntax:

SHIFT

Notes:

The SHIFT command changes the values of the replaceable batch parameters %0 - %9 by copying each parameter into the previous one. In other words, the value of %1 is copied to %0, the value of %2 is copied to %1, and so on. This is useful for writing a batch file that performs the same operation on any number of parameters.

You can also use the SHIFT command to create a batch file that can accept more than 10 parameters. If you specify more than 10 parameters on the command line, those that appear after the tenth (%9) will be shifted one at a time into %9.

There is no backward SHIFT command. Once you carry out the SHIFT command, you cannot recover the first parameter (%0) that existed before the shift.

Example:

The following batch file, MYCOPY.BAT, shows how to use the SHIFT command with any number of parameters. It copies a list of files to a specific directory. The parameters are the directory name followed by any number of filenames.

@echo off
SET todir=%1
:getfile
SHIFT
IF "%1"=="" GOTO end
COPY %1 %todir%
GOTO getfile
:end
SET todir=
ECHO All done

File Details:

Internal


If you should have any comments or suggestions,
please contact: Bob Watson
.
This page last revised:
December 9, 1999.