Fix regression introduced in 5749d9e

This commit is contained in:
Ethan P 2019-09-08 19:15:48 -07:00
parent d38d5b518e
commit 469a6fc65f
No known key found for this signature in database
GPG Key ID: 1F8DF8091CD46FBC

View File

@ -7,11 +7,12 @@
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
PROGRAM="$(basename "${BASH_SOURCE[0]}")" PROGRAM="$(basename "${BASH_SOURCE[0]}")"
# Sets the internal _ARGV and _ARGV_INDEX variables used when # Sets the internal _ARGV, _ARGV_INDEX, and _ARGV_LAST variables used when
# parsing options with the shiftopt and shiftval functions. # parsing options with the shiftopt and shiftval functions.
setargs() { setargs() {
_ARGV=("$@") _ARGV=("$@")
_ARGV_INDEX="$((${#_ARGV[@]} - 1))" _ARGV_LAST="$((${#_ARGV[@]} - 1))"
_ARGV_INDEX=0
} }
# Gets the next option passed to the script. # Gets the next option passed to the script.
@ -30,7 +31,7 @@ setargs() {
# done # done
shiftopt() { shiftopt() {
# Read the top of _ARGV. # Read the top of _ARGV.
[[ "$_ARGV_INDEX" -lt 0 ]] && return 1 [[ "$_ARGV_INDEX" -gt "$_ARGV_LAST" ]] && return 1
OPT="${_ARGV[$_ARGV_INDEX]}" OPT="${_ARGV[$_ARGV_INDEX]}"
unset OPT_VAL unset OPT_VAL
@ -40,7 +41,7 @@ shiftopt() {
fi fi
# Pop array. # Pop array.
((_ARGV_INDEX--)) ((_ARGV_INDEX++))
return 0 return 0
} }
@ -59,7 +60,7 @@ shiftval() {
fi fi
OPT_VAL="${_ARGV[$_ARGV_INDEX]}" OPT_VAL="${_ARGV[$_ARGV_INDEX]}"
((_ARGV_INDEX--)) ((_ARGV_INDEX++))
# Error if no value is provided. # Error if no value is provided.
if [[ "$OPT_VAL" =~ -.* ]]; then if [[ "$OPT_VAL" =~ -.* ]]; then