getopts checking for mutually exclusive arguments getopts checking for mutually exclusive arguments bash bash

getopts checking for mutually exclusive arguments


I can think of 2 ways:

Accept an option like -t <argument> Where argument can be desktop or minimal

So your script will be called as:

./scriptname.sh -t desktop -n

OR

./scriptname.sh -t minimal -n

Another alternative is to enforce validation inside your script as this:

headless=buildtype=while getopts 'mdnh' flag; do  case "$flag" in    m) [ -n "$buildtype" ] && usage || buildtype='minimal' ;;    d) [ -n "$buildtype" ] && usage || buildtype='desktop' ;;    n) headless=1 ;;    h) usage ;;    \?) usage ;;    *) usage ;;  esacdone