From 6d9c899aa8a8d14ad054d953e3eabef6e0dbdb06 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 26 May 2015 17:45:29 -0400 Subject: 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. --- 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 -- cgit v0.9.1