bash 如何将参数传递给java bash脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27344194/
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-18 11:57:29  来源:igfitidea点击:

How to pass argument to java bash script?

javabash

提问by Aaron

I have a simple bash script which runs my java program. Here is it:

我有一个简单的 bash 脚本来运行我的 java 程序。就这个:

run.sh

运行文件

#!/bin/sh
java -jar target/my-jar-arch.jar

I want to pass arguments to this script, which must pass them to java program:

我想将参数传递给这个脚本,它必须将它们传递给 java 程序:

bash run.sh myArg -key 100

When I try to execute this line my app doesn't get any parameters. How can I fix it?

当我尝试执行这一行时,我的应用程序没有获得任何参数。我该如何解决?

回答by fge

Change your invocation line to:

将您的调用行更改为:

java -jar target/my-jar-arch.jar "$@"