This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Changes the position of batch parameters in a batch file.
shift [/n <N>]| Parameter | Description |
|---|---|
/n<N> | Specifies to start shifting at theNth argument, whereN is any value from0 to8. Requires command extensions, which are enabled by default. |
| /? | Displays help at the command prompt. |
Theshift command changes the values of the batch parameters%0 through%9 by copying each parameter into the previous one—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.
If command extensions are enabled, theshift command supports the/n command-line option. The/n option specifies to start shifting at the Nth argument, whereN is any value from 0 to 8. For example,SHIFT /2 would shift%3 to%2,%4 to%3, and so on, and leave%0 and%1 unaffected. Command extensions are enabled by default.
You can use theshift 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.
Theshift command has no effect on the%* batch parameter.
There's no backwardshift command. After you implement theshift command, you can't recover the batch parameter (%0) that existed before the shift.
To use a batch file, calledMycopy.bat, to copy a list of files to a specific directory, type:
@echo offrem MYCOPY.BAT copies any number of filesrem to a directory.rem The command uses the following syntax:rem mycopy dir file1 file2 ...set todir=%1:getfileshiftif "%1"=="" goto endcopy %1 %todir%goto getfile:endset todir=echo All doneWas this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?