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 ... 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 "$@" @ should "always" be quoted: "$@", otherwise is not different from $*. Also, should be mentioned that after the shift, if not previously saved, the first parameter is lost.$@.You can pass second argument onwards without using "shift" as well.
set -- 1 2 3 4 5 echo "${@:0}" echo "${@:1}" echo "${@:2}" # here sh, only bash. this is called substring expansion and has a special behaviour for @. usually it counts the characters, but for @ it counts the parameters.Substring Extraction ${string:position} Extracts substring from $string at $position. If the $string parameter is "*" or "@", then this extracts the positional parameters, [1] starting at $position.