Changes the position
of batch parameters in a batch file.
- Using the
shift command-line option with command extensions
When command extensions are enabled (that
is, the default), the shift command supports the
/n command-line option, which tells the command to start
shifting at the nth argument, where n can be a
value from zero to eight. For example,
would shift %3 to %2, %4 to %3, and so
on, and leave %0 and %1 unaffected.
- How the shift
The shift command changes the
values of the batch parameters %0 through %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.
- Working with
more than 10 batch parameters
You can also use the shift command
to create a batch file that can accept more than 10 batch
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.
no affect on the %* batch parameter.
There is no backward shift
command. After you carry out the shift command, you
cannot recover the first batch parameter (%0) that existed
before the shift.
The following batch
file, Mycopy.bat, shows how to use shift with any
number of batch parameters. It copies a list of files to a
specific directory. The batch parameters are represented by
the directory and file name arguments.
rem MYCOPY.BAT copies any number of files
rem to a directory.
rem The command uses the following syntax:
rem mycopy dir file1 file2 ...
if "%1"=="" goto end
copy %1 %todir%
echo All done