How do I pass the entire argument list of shell script to a program?
So for instance, if I have a java program called JavaFoo that’d take any number of arguments, and this should be called inside my script.
How do I pass the script’s arguments to the java program?
In Bash:
to pass all parameters individually quoted as passed to the Bash script itself.
Works with Dash as well, but I don’t know about other Bourne-compatible shells.
Say you want to pass all but the first parameter to the shell script on to the Java program, use
shiftlike this:Use more instances of
shiftto get rid of more parameters before passing them on, if needed.So say you call the shell script (
myscript) as follows:the
shiftwill get rid ofa. Add one moreshiftand it also gets rid ofb. The name of the script itself is not included in"$@"even though you can access it as$0in many shells.