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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:08:18  来源:igfitidea点击:

What are "%1" and "%2" in batch files?

windowsbatch-file

提问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

%1becomes "firstArg" and %2becomes "secondArg"

%1变为“firstArg”并%2变为“secondArg”

The related shiftcommand shifts the position of arguments one to the left. Running shiftonce 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

%1is the first argument given, %2the 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.