I have a common library that I use from several scripts that parses command line options, however I also want my individual scripts to be able to process arguments as well... e.g.
common.sh:
function get_options {
echo -e "in getoptions"
echo $OPTIND
while getopts ":ab:" optionName; do
[ ... processing code ... ]
done
}
a.sh
. ./common.sh
function get_local_options {
echo -e "in getoptions"
echo $OPTIND
while getopts ":xy:" optionName; do
[ ... processing code ... ]
done
}
get_local_options $*
OPTIND=1
get_options $*
The problem si that if I call a.sh with:
a.sh -x -y foo -a -b bar
get_options stops processing at "foo" as it stops at the first "non-option"
Any way around this without rewriting things myself?