Shift command in Windows

Shift helps to change the position of batch parameters in a batch file.

Shift helps to change the position of batch parameters in a batch file. To better understand how to use this command, see the example below.

Shift command syntax

 shift [/ n] 

Shift command parameter

Parameters

Describe

/ n

Specifies start conversion at argument N, where N is any value from 0 to 8. This parameter requires command extensions (enabled by default).

/?

Show help at thecommand prompt.

Note the shift command

  1. Shift command changes the values ​​of batch parameters% 0 to% 9 by copying each of these parameters into a previous parameter, the value of% 1 is copied to% 0, the value of% 2 is copy to% 1, etc.
  2. If the command extension is enabled, the shift command will support the command line option / n.The / n option will specify the start of the shift process at argument N, where N is any value from 0 to 8. For example, SHIFT / 2 will convert% 3 to% 2,% 4 to% 3, etc. 0 and% 1 will not be affected.Command extension is enabled by default.
  3. You can 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, the parameters appear after the tenth (% 9), each time one of them will be converted to% 9.
  4. The shift command will not affect the batch parameter% *.
  5. There is no reverse shift command (reverse shift command). After you execute the shift command, you cannot restore the batch parameter (% 0) that existed before the change.

Shift command example

The following command from the sample batch file named Mycopy.bat shows how to use the shift command with any number of batch parameters.In this example, Mycopy.bat copies the list of files to a specific directory. The batch parameters will be represented by the directory and file name arguments.

 @echo off 
rem MYCOPY.BAT copies any number of files
rem để một thư mục.
rem The câu lệnh dùng một câu lệnh sau:
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

See more:

  1. How to create disk full BAT file repair Windows 10
  2. How to use Command Prompt to manage wireless networks on Windows 10?
  3. Access Windows Remote Desktop via Internet
  4. Summary of tips to fix slow computer errors on Windows
4.5 ★ | 2 Vote