From 9979838ec4fae83f664b70133d93feb3cb8dd0ab Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Mon, 5 Feb 2018 01:42:17 +0900 Subject: [PATCH] Fix attemptd assignment to non-variable in bash 3 (#628) * 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 > --- bash_completions.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bash_completions.go b/bash_completions.go index c19fe7a..81bfb61 100644 --- a/bash_completions.go +++ b/bash_completions.go @@ -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