? used in getopts

Suppose I have a code below .

while getopts a: opt
do
   case $opt in
   a) app_name="$OPTARG";;
   *) echo "$opt is an invalid option";
      exit 1;;
   ?) echo "The value of $OPTARG is an invalid option";
      exit 1;;
   esac
done

Could anyone please tell me in which case my script will give output for ? option . Suppose I run my script abc.sh containing this code like this :- sh abc.sh -a
The argument for a is null and I am getting output like ? is an invalid option .So in which case I should get output for ? opt (ie; The value of $OPTARG is an invalid option)

I'm pretty sure the answer is "never". Your * option is above it, and since * accepts anything, it always gets picked first.

Your arg string of "a:" means that a always requires a parameter though, so getopts will never accept it unless you do -a something .

I'm not sure what your ?) is for but beware that it doesn't match just a literal question mark -- it matches any single character.