Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

shift

Feedback

In this article

Changes the position of batch parameters in a batch file.

Syntax

shift [/n <N>]

Parameters

ParameterDescription
/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.

Remarks

  • 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.

Examples

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 done

Related links


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?