Posted On 2007-04-24 by FortyPoundHead
Keywords: Command Reference
Tags: Windows Commandline Windows
Views: 1434

Change the position of command line parameters in a batch file.

SHIFT [/n]for example:
given %1=one, %2=two, %3=three...
will result in %1=two, %2=three

alternatively given %1=one, %2=two, %3=three...
will result in %1=three

/n tells the SHIFT command to start shifting at the nth argument, where n may be between zero and eight.

for example:
given %1=one, %2=two, %3=three, %4=four...
will result in %1=one, %2=three, %3=four

%0 is the name of the batch file itself - %1 can be shifted into %0

Relative pathnames

The parameter %0 will initially refer to the path that was used to execute the batch - this could be MyBatch.cmd if in the current directory or a full path like C:\apps\myBatch.cmd

When SHIFT is used to move a text parameter into %0 then references to %0 will refer to the current working directory, unless those parameters happen to contain a valid path.

For example:


will run the executable from the same directory

If the following parameter is passed to myBatch.cmd

myBatch.cmd D:\utils\

Then the following commands in myBatch will run MyExecutable.exe from the directory D:\utils\


If Command Extensions are disabled, the SHIFT command will not support the /n switch

About the Author

FortyPoundHead has posted a total of 1974 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links