如何获取参数列表? [英] How to get list of arguments?
问题描述
我想找到Bash的 $ @
的Windows批处理副本,其中包含传递给脚本的所有参数的列表.
I'd like to find a Windows batch counterpart to Bash's $@
that holds a list of all arguments passed into a script.
还是我不得不为 shift
烦恼?
推荐答案
dancavallaro 正确,%*
用于所有命令行参数(脚本名称本身除外).您可能还会发现这些有用:
dancavallaro has it right, %*
for all command line parameters (excluding the script name itself). You might also find these useful:
%0
-用于调用批处理文件的命令(可以是 foo
, .. \ foo
, c:\ bats \ foo.bat
等)%1
是第一个命令行参数,%2
是第二个命令行参数,
依此类推,直到%9
(和 SHIFT
都可用于9号之后的代码).
%0
- the command used to call the batch file (could be foo
, ..\foo
, c:\bats\foo.bat
, etc.)
%1
is the first command line parameter,
%2
is the second command line parameter,
and so on till %9
(and SHIFT
can be used for those after the 9th).
%〜nx0
-批处理文件的实际名称,与调用方法无关(some-batch.bat)%〜dp0
-脚本的驱动器和路径(d:\ scripts)%〜dpnx0
-是脚本的标准路径名(d:\ scripts \ some-batch.bat)
%~nx0
- the actual name of the batch file, regardless of calling method (some-batch.bat)
%~dp0
- drive and path to the script (d:\scripts)
%~dpnx0
- is the fully qualified path name of the script (d:\scripts\some-batch.bat)
有关更多信息示例,请参见 https://www.ss64.com/nt/syntax-args.html 和 https://www.robvanderwoude.com/parameters.html
More info examples at https://www.ss64.com/nt/syntax-args.html and https://www.robvanderwoude.com/parameters.html
这篇关于如何获取参数列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!