I want to use getopts in a Bash script as follows:
while getopts ":hXX:h" opt; do
case ${opt} in
hXX ) Usage
;;
h ) echo "You pressed Hey"
;;
\? ) echo "Usage: cmd [-h] [-p]"
;;
esac
done
The idea behind is that I want to have two flags -h
or --help
for allowing user to be able to use HELP in order to be guided how to use the script and another second flag which starts with h
but its like -hxx
where x
is whatever.
How can I distinguish these two since even when I press --hxx
flag it automatically executes help flag. I think the order of presenting them in getopt
has nothing to do with this.