SHIFT
Changes the position of replaceable parameters in a batch program.
Syntax
SHIFT
SHIFT─Notes
How the SHIFT command works
The SHIFT command changes the values of replaceable parameters %0 to %9 by copying each parameter to the previous parameter. That is, the value of %1 is copied to %0, the value of %2 is copied to %1, and so on. This command is useful for batch files that perform the same operation on a series of parameters.
:m567
Using more than 10 command-line parameters
Using the SHIFT command, a batch file can also receive more than 10 command-line parameters. If the specified command-line parameters exceed 10, then the parameters appearing after the 10th parameter (%9) will in turn be shifted into (%9).
Restoring replaceable parameters
The SHIFT command is irreversible. Once the SHIFT command has been executed, the first parameter before the SHIFT command (%0) cannot be restored.
SHIFT─Example
The following batch file MYCOPY.BAT shows how to use the SHIFT command to process any number of command-line parameters and copy a series of files to a specified directory. The parameters used are the directory name followed by a series of file names.
@echo off
rem MYCOPY.BAT copies any number of files
rem to a directory。
rem The command uses the following syntax:
rem mycopy dir file1 file2 ...
set todir=%1
:getfile
shift
if "%1"=="" goto end
copy %1 %todir%
goto getfile
:end
set todir=
echo All done