Board logo

标题: [求助]请问shift这个批处理命令的用法? [打印本页]

作者: doslr     时间: 2004-11-8 00:00    标题: [求助]请问shift这个批处理命令的用法?

我实在弄不懂shift这个命令的用法??
哪位达人能教我这个shift命令是怎么样用的吗??
最后能附带一个实例.谢谢!
作者: autoit     时间: 2004-11-9 00:00
Changes the position of replaceable parameters in a batch file.SHIFT [/n]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 may be between zero and eight.  For example:    SHIFT /2would shift %3 to %2, %4 to %3, etc. and leave %0 and %1 unaffected.

作者: Climbing     时间: 2004-11-10 00:00
在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 [/n]如果命令扩展被启用,SHIFT 命令支持/n 命令行开关;该命令行开关告诉
命令从第 n 个参数开始移位;n 介于零和八之间。例如:    SHIFT /2会将 %3 移位到 %2,将 %4 移位到 %3,等等;并且不影响 %0 和 %1。
作者: doslr     时间: 2004-11-12 00:00
谢谢Climbing!!!!