bash 将第二个参数从 shell 脚本传递给 Java

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

Passing second argument onwards from a shell script to Java

bash

提问by cm_c

If I pass any number of arguments to a shell script that invokes a Java program internally, how can I pass second argument onwards to the Java program except the first?

如果我将任意数量的参数传递给在内部调用 Java 程序的 shell 脚本,如何将第二个参数继续传递给 Java 程序,但第一个参数除外?

./my_script.sh a b c d ....

./my_script.sh abcd ....

#my_script.sh
...
java MyApp b c d ...

回答by Bolo

First use shiftto "consume" the first argument, then pass "$@", i.e., the list of remaining arguments:

首先使用shift“消耗”第一个参数,然后传递"$@",即剩余参数的列表:

#my_script.sh
...
shift
java MyApp "$@"

回答by bashfu

You can pass second argument onwards without using "shift" as well.

您也可以在不使用“shift”的情况下继续传递第二个参数。

set -- 1 2 3 4 5

echo "${@:0}"
echo "${@:1}"
echo "${@:2}"   # here