I have a bash script where you can specify options with “–option parameter”:
if [ ${1:0:2} != '--' ] ; then
echo -e "Unrecognized option: $1\n$requestHelpMessage"; exit 1;
fi
if [ ! $2 ];
then echo -e "Expected parameter for $1\n$requestHelpMessage"; exit 1;
fi
case ${1:2} in
branch) # do something with $2 here
batch) # do something with $2 here
version) # do something with $2 here
*) # you get the idea
esac
And I want to extend it to be able to handle “–option=parameter” as well. Is there an easy way to split over “=” without special-casing each one?
Instead of using getopt or making your own setup, try using “getopt“. It supports both long (word) and short (character) arguments.
Here’s an example of it in use: