getopts
getopts is used by shell procedures to parse positional parameters as options.[1]
Documentation
- getopts [EN] @ GNU Bash Reference Manual
- bash -c 'help getopts'
- man 1 'bash' [EN]
Further Information
Examples
while getopts 'abc:d:Dhl:qp:Prs:vV' option; do
case $option in
a ) all=1 ;;
b ) backup=1 ;;
c ) conf_file="$OPTARG" ;;
d ) dst_path="$OPTARG" ;;
D ) dry_run=1 ;;
h ) help=1 ;;
l ) log_file="$OPTARG" ;;
q ) quiet=1 ;;
p ) profiles+="$OPTARG " ;;
P ) print_profiles=1 ;;
r ) restore=1 ;;
s ) src_path="$OPTARG" ;;
v ) verbose=1 ;;
V ) version=1 ;;
* ) usage; exit 1 ;;
esac
done
References
- ↑ bash -c 'help getopts'