From 8ffad3520117d00bd47a2f60abe7c8170d903853 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Mon, 26 Aug 2013 09:55:44 +0100 Subject: [PATCH] ZSH compatibility issue determining array length affecting bootstrap and current command. --- src/main/bash/gvm-current.sh | 6 +----- src/main/bash/gvm-init.sh | 12 +++++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/bash/gvm-current.sh b/src/main/bash/gvm-current.sh index e7dcdfa4..04a92686 100644 --- a/src/main/bash/gvm-current.sh +++ b/src/main/bash/gvm-current.sh @@ -45,12 +45,8 @@ function __gvmtool_current { echo "Not using any version of ${CANDIDATE}" fi else - # The candidates are assigned to an array for zsh compliance, a list of words is not iterable - # Arrays are the only way, but unfortunately zsh arrays are not backward compatible with bash - # In bash arrays are zero index based, in zsh they are 1 based(!) INSTALLED_COUNT=0 - # Starts at 0 for bash, ends at the candidate array size for zsh - for (( i=0; i <= ${#GVM_CANDIDATES}; i++ )); do + for (( i=0; i <= ${GVM_CANDIDATE_COUNT}; i++ )); do # Eliminate empty entries due to incompatibility if [[ -n ${GVM_CANDIDATES[${i}]} ]]; then __gvmtool_determine_current_version "${GVM_CANDIDATES[${i}]}" diff --git a/src/main/bash/gvm-init.sh b/src/main/bash/gvm-init.sh index 5df3986f..b290ba33 100644 --- a/src/main/bash/gvm-init.sh +++ b/src/main/bash/gvm-init.sh @@ -153,10 +153,16 @@ fi # Build _HOME environment variables and prefix them all to PATH +# The candidates are assigned to an array for zsh compliance, a list of words is not iterable +# Arrays are the only way, but unfortunately zsh arrays are not backward compatible with bash +# In bash arrays are zero index based, in zsh they are 1 based(!) gvm_set_candidates - -# bash/zsh hack: Starts at 0 for bash, ends at the candidate array size for zsh -for (( i=0; i <= ${#GVM_CANDIDATES}; i++ )); do +if [[ -z "$ZSH_VERSION" ]]; then + GVM_CANDIDATE_COUNT=${#GVM_CANDIDATES[@]} +else + GVM_CANDIDATE_COUNT=${#GVM_CANDIDATES} +fi +for (( i=0; i <= ${GVM_CANDIDATE_COUNT}; i++ )); do # Eliminate empty entries due to incompatibility if [[ -n ${GVM_CANDIDATES[${i}]} ]]; then CANDIDATE_NAME="${GVM_CANDIDATES[${i}]}"