windows - 在 CMD 批处理脚本中调用标签时如何使用超过 9 个参数?

标签 windows batch-file command-line-arguments

我想知道在调用标签时如何在批处理脚本中调用超过 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/

相关文章:

windows - 如何在 Delphi 中打开 MSI 表?

batch-file - 我需要脚本来处理所有 dav 文件

windows-7 - 批处理文件命令 PAUSE 不起作用

bash - 在 Bash shell 脚本中传播所有参数

python - 在 Python 中自动打开作为命令行参数给出的文件

c - 如何通过 Windows 批处理文件将值传递给 scanf()

c# - 替换MySQL数据库中的特定值

regex - 从批处理脚本中的字符串中提取数字

c# - 如何清除列表框中的所有数据?

java - 从 Java 使用时 Windows 2008 Server 上 %~dp0 的行为