I want to design a shell script as a wrapper for a couple of scripts. I would like to specify parameters for
myshell.sh -h hostname -s test.sh -d waittime param1 param2 param3
myshell.sh param1 param2 -h hostname param3 -d waittime -s test.sh
myshell.sh param1 -h hostname -d waittime -s test.sh param2 param3
test.sh param1 param2 param3
Sorry for commenting on an old thread, but thought I'd post for those, like me who were searching on how to do this...
Essentially if you want to do something like:
script.sh [options] ARG1 ARG2
Then get your options like this:
while getopts "h:u:p:d:" flag; do case "$flag" in h) HOSTNAME=$OPTARG;; u) USERNAME=$OPTARG;; p) PASSWORD=$OPTARG;; d) DATABASE=$OPTARG;; esac done
And then you can get your positional arguments like this:
More information and details are available through the link above.
Hope that helps!!