Are there some built-in tools that will recognize
--xxxx as switches, and not arguments, or do you have to go through all the input variables, test for dashes, and then parse the arguments thereafter?
It is fairly portable as it is in the POSIX spec. Unfortunately it doesn’t support long options.
If you only need short options, typical usage pattern for
getopts (using non-silent error reporting) is:
# process arguments "$1", "$2", ... (i.e. "[email protected]") while getopts "ab:" opt; do case $opt in a) aflag=true ;; # Handle -a b) barg=$OPTARG ;; # Handle -b argument ?) ;; # Handle error: unknown option or missing required argument. esac done