I went back and read your entire question and realized that I had originally answered a question slightly different than the one you asked, so here goes:
Your structure is fine. Parse the command option at the beginning of the script.
Yes, you can use a
casestatement, checking against
$1(see my original answer below), although if you are only planning a single option, you can just as easily perform a single test (see my original answer below). To use a
casestatement with multiple possible options, place it in a
whileloop, in the form
while "$1" ; do case ... esac; shift; done. The
shiftcommand will replace
$1with the next word / option from your command line.
There are several ways of dealing with this. If this is the only option, or if there are only a few, you may consider parsing it manually yourself. In shell-speak, all words after the shell command are called parameters, and each is assigned to a positional parameter, in the form
n starting at 1. Thus, you can perform a test to check whether
[[ $1 == "--nomail" ]] and act accordingly. That's the simple straightforward way for only a single option.
For more complex shell scripts with many options, you may want to avail yourself of some form of
getopts command to parse the options for you. The
bash shell includes a version of
getopts as a builtin, and you can learn more about it by typing
man bash at the command line and then (if your default pager is set to