China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 09:46
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Please tell me the usage of the shift batch command? View 3,943 Replies 3
Original Poster Posted 2004-11-08 00:00 ·  中国 广西 桂林 电信
初级用户
Credits 168
Posts 27
Joined 2004-11-03 00:00
21-year member
UID 33247
Gender Male
Status Offline
I really don't understand the usage of the shift command??
Can any expert teach me how the shift command is used?
Finally, can you attach an example. Thanks!
Floor 2 Posted 2004-11-09 00:00 ·  中国 福建 厦门 电信
系统支持
★★★
Credits 904
Posts 339
Joined 2002-10-10 00:00
23-year member
UID 1904
From 厦门
Status Offline
更改批处理文件中可替换参数的位置。SHIFT 如果启用了命令扩展,SHIFT命令支持/n开关,该开关告诉命令从第n个参数开始移位,其中n可以在0到8之间。例如:SHIFT /2会将%3移到%2,%4移到%3,等等,并且不影响%0和%1。

The SHIFT command changes the position of replaceable parameters in a batch file. SHIFT If Command Extensions are enabled, the SHIFT command supports the /n switch, which tells the command to start shifting at the nth argument, where n can be between 0 and 8. For example: SHIFT /2 would shift %3 to %2, %4 to %3, etc., and leave %0 and %1 unaffected.
Floor 3 Posted 2004-11-10 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
In batch processing of DOS, only 9 command-line parameters from %1 to %9 are supported (%0 is used to represent the command itself). If you want your batch to support more than 9 command-line parameters, you need to use the shift command. Each time the shift command is run, the command-line parameters shift left by one position, that is, %2 becomes %1, %3 becomes %2, and so on. A simple example: You create a batch file, suppose it is named tstshift.bat, and the content is as follows:
@echo off
echo %0
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
echo %1
::1
shift
echo %1
::2
shift
echo %1
::3
shift
echo %1
::4
shift
echo %1
::5
shift
echo %1
::6
shift
echo %1
::7
shift
echo %1
::8
shift
echo %1
::9
shift
echo %1
::10
shift
echo %1
Then run:
tstshift 0 1 2 3 4 5 6 7 8 9 a The running result is as follows:
D:\>tstshift 0 1 2 3 4 5 6 7 8 9 a
tstshift
0 1 2 3 4 5 6 7 8
0
1
2
3
4
5
6
7
8
9
a The above are all the functions supported by the shift command. And the shift function under 2000/xp/2003 has a new /n parameter, which is used to specify starting from the nth parameter for shifting. The Chinese help of the shift command under 2000/xp/2003 is:
D:\>shift /?
Change the position of replaceable parameters in a batch file. SHIFT If command extensions are enabled, the SHIFT command supports the /n command-line switch; this command-line switch tells
The command to shift starting from the nth parameter; n is between zero and eight. For example: SHIFT /2 would shift %3 to %2, shift %4 to %3, and so on; and it does not affect %0 and %1.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 4 Posted 2004-11-12 00:00 ·  中国 广西 柳州 电信
初级用户
Credits 168
Posts 27
Joined 2004-11-03 00:00
21-year member
UID 33247
Gender Male
Status Offline
Forum Jump: