Google has finally failed me. I cannot seem to find how to do this in Bourne shell scripting:
I am writing a shell script to handle all of my testing for a project. I’ve set up functions for each task that this script could do (build, run, clean, etc), and would like to pass any additional command-line parameters (besides the command itself) onto the desired function.
Example:
./test.sh build -j should pass -j into the build function.
A pseudo-code version of this logic would look like:
function build() {
make $*
}
if [ $1 == 'build' ]; then
build $2 -> $N
fi
How can I accomplish this?
I think you could achieve this effect using the
shiftcommand. It will move all of the positional parameters down one place and drops the value of$1(so the value of$3gets moved to$2, the value of$2gets moved to$1and the value of$1is lost). Once you’ve done that you can just use$@to pick up the list of arguments you’re actually interested in e.g.