windows 批处理文件中的“%1”和“%2”是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2309968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are "%1" and "%2" in batch files?
提问by Ricky
What does the following %1means (in a .bat file)?
以下%1是什么意思(在 .bat 文件中)?
jsmin <%1 >%2
回答by Mehrdad Afshari
It represents the first command line argument passed to the batch file.
它代表传递给批处理文件的第一个命令行参数。
If you run your batch file with:
如果您使用以下命令运行批处理文件:
myfile.bat firstArg secondArg
%1
becomes "firstArg" and %2
becomes "secondArg"
%1
变为“firstArg”并%2
变为“secondArg”
The related shift
command shifts the position of arguments one to the left. Running shift
once in a batch file will make "%1" value to be the second argument, "%2" becomes the third, and so on. It's useful for processing command line arguments in a loop in the batch file.
相关shift
命令将参数的位置向左移动一位。shift
在批处理文件中运行一次将使“%1”值成为第二个参数,“%2”成为第三个,依此类推。它对于在批处理文件的循环中处理命令行参数很有用。
回答by Tatu Ulmanen
%1
is the first argument given, %2
the second.
%1
是给出的第一个参数,%2
第二个。
If you run the file with foo.bat source.js destination.js
, the command run is jsmin <source.js >destination.js
.
如果使用 运行该文件foo.bat source.js destination.js
,则运行命令为jsmin <source.js >destination.js
.