summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinux User <ziggys@alpine.my.domain>2018-07-14 15:52:26 -0400
committerLinux User <ziggys@alpine.my.domain>2018-07-14 15:52:26 -0400
commit5c60796fb92b1c4420297740e2517d702dcc9549 (patch)
tree4d82d151c853b69409a4d4669e2ddff2f22a5520
parentc355bb0ebf91f027a70d1f6fb4260ee549ebadd1 (diff)
downloadsnippets-5c60796fb92b1c4420297740e2517d702dcc9549.zip
snippets-5c60796fb92b1c4420297740e2517d702dcc9549.tar
Add getopts.sh
-rw-r--r--getopts.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/getopts.sh b/getopts.sh
new file mode 100644
index 0000000..056b136
--- /dev/null
+++ b/getopts.sh
@@ -0,0 +1,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))
+