We have seen how to identify options and parameters, but we still need a way to read the options values correctly.
You may need to pass a value for a specific option. How can this value be read?
We will check for the $2 variable while the iteration goes through the options that we expect a value for.
Check the following code:
#!/bin/bash
while [ -n "$1" ]
do
case "$1" in
-a) echo "-a option passed";;
-b) param="$2"
echo "-b option passed, with value $param"
shift ;;
-c) echo "-c option passed";;
--) shift
break ;;
*) echo "Option $1 not an option";;
esac
shift
done
num=1
for param in "$@"
do
echo "#$num: $param"
num=$(( $num + 1 ))
done

This looks good now; your script identifies the options and the passed value for the second option.
There is a built-in option for getting options from the users, which is using the getopt function.
Unfortunately, getopt doesn't support options with more than one character.
There is a non-built-in program called getopt, which supports options larger than one character, but, again, the macOS X version doesn't support long options.
Anyway, if you would like to read more about getopt usage, refer to the further reading resources given after this chapter.