I've the following simple code:
#!/usr/bin/env bash
while getopts :f arg; do
case $arg in
f) echo Option $arg specified. ;;
*) echo Unknown option: $OPTARG. ;;
esac
done
and it works in simple scenarios such as:
$ ./test.sh -f
Option f specified.
$ ./test.sh -a -f
Unknown option: a.
Option f specified.
However it doesn't work for the following:
$ ./test.sh foo -f
$ ./test.sh -a abc -f
Unknown option: a.
How do I fix above code example to support invalid arguments?