开发者

Passing second argument onwards from a shell script to Java [duplicate]

This question already has answers here: 开发者_如何学编程 Process all arguments except the first one (in a bash script) (5 answers) Closed 7 years ago.

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?

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

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


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

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


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

set -- 1 2 3 4 5

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜