我想知道在调用标签时如何在批处理脚本中调用超过 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。我试过在数字周围使用花括号、方括号、引号、单引号,但都没有成功。
最佳答案
使用 shift
command如果您想使用超过 9 个参数。
(如果算上%0
参数的话其实有10多个参数)
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, those that appear after the tenth (%9) will be shifted one at a time into %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
如果你有很多参数,你可以用循环替换 shift 命令。以下 for 循环执行 shift
九次,因此 %1
将是第十个参数。
@for /L %%i in (0,1,8) do shift
关于windows - 在 CMD 批处理脚本中调用标签时如何使用超过 9 个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8328338/