Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

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 ... 
like image 695
cm_c Avatar asked Oct 22 '10 08:10

cm_c


People also ask

How do I pass multiple arguments to a shell script?

To pass multiple arguments to a shell script you simply add them to the command line: # somescript arg1 arg2 arg3 arg4 arg5 … To pass multiple arguments to a shell script you simply add them to the command line: # somescript arg1 arg2 arg3 arg4 arg5 …

How do you pass a command line argument to a function in shell script?

To invoke a function, simply use the function name as a command. To pass parameters to the function, add space separated arguments like other commands. The passed parameters can be accessed inside the function using the standard positional variables i.e. $0, $1, $2, $3 etc.

What is $@ in bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.


1 Answers

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

#my_script.sh ... shift java MyApp "$@" 
like image 154
Bolo Avatar answered Oct 18 '22 07:10

Bolo