Passing second argument onwards from a shell script to Java

Bash

Bash Problem Overview


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 ...

Bash Solutions


Solution 1 - Bash

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

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

Solution 2 - Bash

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

set -- 1 2 3 4 5

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioncm_cView Question on Stackoverflow
Solution 1 - BashBoloView Answer on Stackoverflow
Solution 2 - BashbashfuView Answer on Stackoverflow