I cannot seem to figure out why my simple bash script is parsing not declared flags. Here is how it looks:
#!/bin/bash 
while getopts "hi" OPTIONS
do
        case $OPTIONS in
                   h)     
                        echo "usage:"
                        echo "./scriptname.sh [options]"
                        echo " "
                        echo "options:"
                        echo "-i              install it"
                        echo "-h              show help menu"
                        exit 0
                        ;;
                   i)     
                        echo "this is function -i"
                        exit 0
                        ;;
                \?)
                        echo "illegal option"
                        exit
                        ;;
        esac
done
What happens is that it works just fine when passing -h and -i, however if typing -isomething and -hsomethingelse it will still return the options declared for h and i, as it seems to be ignoring anything else typed after -i and -h.
Essentially script should only parse -i and -h and return "illegal option" for anything else, even if option starts with either -i or -h, example -hospital.
I tried separating the two letters in while getopts with :, however that way either -i or -h will work, depending how : are positioned.
Example
while getopts "h:i:" OPTIONS
do
Thanks
