getopts

From RaySoft

getopts is used by shell procedures to parse positional parameters as options.[1]

Documentation

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

  1. bash -c 'help getopts'