I am writing a bash script with getopts which contains multiple case statements. My requirement is to be able to decide when getopts can take multiple options and when not.
while getopts "hla:d:t:k:w:e:f:i:m:u:L:D:" options
do
case $options in
h)
if [[ "${OPTARG}" = -* ]]; then
echo "Multiple options are not allowed"
exit 1
fi
verboseHelpAndExit
break
;;
l)
if [[ "${OPTARG}" = -* ]]; then
echo "Multiple options are not allowed"
exit 1
fi
if [ "$#" -gt 0 ] || [ "$1" != '-l' ]; then
echo "No parameters allowed"
else
list_users
fi
break
;;
w)
warn="$OPTARG"
check_for_integer $warn
;;
e)
expire="$OPTARG"
check_for_integer $expire
;;
here -h and -l should not take any other option and should give error if any other option is passed, but -w and -e can take multiple options, What is wrong with my code block?