summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-05-26 17:45:29 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-05-26 17:56:53 (EDT)
commit6d9c899aa8a8d14ad054d953e3eabef6e0dbdb06 (patch)
treeaa574f82b4ec92f483e585283a92e5ec9dc3e085 /lib
parentea54bba72e32bd589818851d693b57d80bedb442 (diff)
get_options(): Handle cases when OPTARG is null
Previously, option variables were set to "true" if an option required an argument but the argument given was null.
Diffstat (limited to 'lib')
-rw-r--r--lib/getopt.sh12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/getopt.sh b/lib/getopt.sh
index 048e02b..b8d90fb 100644
--- a/lib/getopt.sh
+++ b/lib/getopt.sh
@@ -37,11 +37,17 @@ get_options()
unset OPTARG
while getopts "${optstring}" opt; do
- if [ "x${opt}" != 'x?' ]; then
- eval "${prefix}${opt}=\"\${OPTARG:-true}\""
- else
+ if [ "x${opt}" = 'x?' ]; then
return 1
fi
+ case "${optstring}" in
+ *"${opt}:"*)
+ eval "${prefix}${opt}=\"\${OPTARG}\""
+ ;;
+ *)
+ eval "${prefix}${opt}=true"
+ ;;
+ esac
unset OPTARG
done