『第 3 楼』:
使用 LLM 解释/回答一下
在DOS的批处理中,只支持%1 - %9这9个命令行参数(%0用来表示命令本身),如果你想让你的批处理支持超过9个的命令行参数,就需要用到shift命令,每运行shift命令一次,命令行参数就左移一位,即%2变成%1,%3变成%2,...,依次类推。一个简单的例子,你建立一个批处理,假设名为tstshift.bat,内容如下:
@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
然后运行:
tstshift 0 1 2 3 4 5 6 7 8 9 a运行结果如下:
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上面是所有的shift命令都支持的功能,而2000/xp/2003下的shift功能又新增了一个/n参数,用来指定从第n个参数开始移位。2000/xp/2003下的shift命令的中文帮助为:
D:\>shift /?
更改批处理文件中可替换参数的位置。SHIFT 如果命令扩展被启用,SHIFT 命令支持/n 命令行开关;该命令行开关告诉
命令从第 n 个参数开始移位;n 介于零和八之间。例如: SHIFT /2会将 %3 移位到 %2,将 %4 移位到 %3,等等;并且不影响 %0 和 %1。
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.
|