Skip to content

Commit

Permalink
Fix attemptd assignment to non-variable in bash 3 (spf13#628)
Browse files Browse the repository at this point in the history
* Fix attemptd assignment to non-variable in bash 3

flaghash variable is an associative array which is only supported in
bash > 3.

* Use -gt instead of >
  • Loading branch information
superbrothers authored and eparis committed Feb 4, 2018
1 parent 3a7eb14 commit 9979838
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bash_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,15 @@ __handle_flag()
fi
# keep flag value with flagname as flaghash
if [ -n "${flagvalue}" ] ; then
flaghash[${flagname}]=${flagvalue}
elif [ -n "${words[ $((c+1)) ]}" ] ; then
flaghash[${flagname}]=${words[ $((c+1)) ]}
else
flaghash[${flagname}]="true" # pad "true" for bool flag
# flaghash variable is an associative array which is only supported in bash > 3.
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
if [ -n "${flagvalue}" ] ; then
flaghash[${flagname}]=${flagvalue}
elif [ -n "${words[ $((c+1)) ]}" ] ; then
flaghash[${flagname}]=${words[ $((c+1)) ]}
else
flaghash[${flagname}]="true" # pad "true" for bool flag
fi
fi
# skip the argument to a two word flag
Expand Down

0 comments on commit 9979838

Please sign in to comment.