summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))
+