That's the default of the case
statement, but it means something specific in the context of getopts
: That you have an option defined but no clause to handle it.
If you run ./myTask -z
, for example, you will see the output of "default" as @that_other_guy states in another answer here.
If you want to output something that indicates that no option was supplied:
Then after the while getopts
block but before the shift $(($OPTIND - 1))
line, do this (with whatever processing you want inside the if
block:
if ((OPTIND == 1))
then
echo "No options specified"
fi
Note that this does not indicate that no arguments were specified (e.g. ./myTask
as in your question). To do something with that, add this after the shift
line:
if (($# == 0))
then
echo "No positional arguments specified"
fi
Please see a reference implementation of a getopts
function in my answer here.