我想知道如何在调用标签时在批处理脚本中调用超过 9 个参数。例如,下面显示我分配了 12 个参数,并尝试回显所有这些参数。
CALL:LABEL "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve"
PAUSE
GOTO:EOF
:LABEL
echo %1
echo %2
echo %3
echo %4
echo %5
echo %6
echo %7
echo %8
echo %9
echo %10
echo %11
echo %12
%10 %11 和 %12 的输出最终为 one0 one1 one2。我尝试过在数字周围使用大括号、方括号、引号、单引号,但没有任何运气。
Use the shift command http://technet.microsoft.com/en-us/library/bb491002.aspx如果你想使用超过 9 个参数。
(如果算上的话,实际上有10多个参数%0
范围)
您可以[...]使用shift命令创建一个可以接受10个以上批处理参数的批处理文件。如果在命令行上指定超过 10 个参数,则出现在第十个 (%9) 之后的参数将一次移动一个到 %9。
您可以使用循环,在移位之前存储变量,或者像这样快速执行:
@echo off
CALL:LABEL "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve"
PAUSE
GOTO:EOF
:LABEL
:: print arguments 1-9
echo %1
echo %2
echo %3
echo %4
echo %5
echo %6
echo %7
echo %8
echo %9
:: print arguments 10-11
shift
shift
echo %8
echo %9
:: print argument 13
shift
echo %9
如果您有很多参数,您可以用循环替换移位命令。下面的for循环执行shift
九次,这样%1
将是第十个参数。
@for /L %%i in (0,1,8) do shift
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)