summaryrefslogtreecommitdiff
path: root/getopts.sh
blob: 056b1368aef408e903bf48ad2c1041768d981244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# FIXME: edit options and variables accordingly
# FIXME: options that requires arguments must be defined between ::

# read options from commandline
test "$#" -lt 1 && usage "$@"
while getopts ":a:b:c:dh" opt; do
  case "${opt}" in
    a) VAR="${OPTARG}" ;;
    b) VAR="${OPTARG}" ; commands ;;
    c) VAR="${OPTARG}" ; and_function ;;
    d) commands ; and_or_function ;;
    \?) printf "Invalid: -%s" "${OPTARG}" 1>&2 ; exit 3 ;;
    :) printf "Invalid: -%s requires an argument" "${OPTARG}" 1>&2 ; exit 3 ;;
    h) usage "$@" ;;
  esac
done
shift $((OPTIND -1))