Passing second argument onwards from a shell script to Java [duplicate]
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
精彩评论