getopt - KineticTheory/Linux-HPC-Env GitHub Wiki
Introduction
getopt
provides an easy to use mechanism for parsing command line arguments for bash scripts.
Example
##---------------------------------------------------------------------------##
## Default values
##---------------------------------------------------------------------------##
build_autodoc="off"
build_type=Debug
dashboard_type=Experimental
projects="draco"
extra_params=""
regress_mode="off"
epdash=""
scratchdir=`selectscratchdir`
prdash="-"
unset nfb
##---------------------------------------------------------------------------##
## Command options
##---------------------------------------------------------------------------##
while getopts ":ab:d:e:f:ghp:r" opt; do
case $opt in
a) build_autodoc="on";;
b) build_type=$OPTARG ;;
d) dashboard_type=$OPTARG ;;
e) extra_params=$OPTARG
epdash="-";;
f) featurebranches=$OPTARG
nfb=`echo $featurebranches | wc -w` ;;
h) print_use; exit 0 ;;
p) projects=$OPTARG ;;
r) regress_mode="on" ;;
\?) echo "" ;echo "invalid option: -$OPTARG"; print_use; exit 1 ;;
:) echo "" ;echo "option -$OPTARG requires an argument."; print_use; exit 1 ;;
esac