2 of 2 Respond to actual question at bottom of op


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:

  1. Your structure is fine. Parse the command option at the beginning of the script.

  2. Yes, you can use a case statement, 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 case statement with multiple possible options, place it in a while loop, in the form while "$1" ; do case ... esac; shift; done. The shift command will replace $1 with the next word / option from your command line.

Original answer

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 with 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 less) /^ *getopt.