diff --git a/lib/functions.sh b/lib/functions.sh index a1124ce..e3c3dd3 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -6,11 +6,21 @@ # containsElement ARRAY 'a' => 0 containsElement () { local -a 'arraykeys=("${!'"$1"'[@]}")' - for index in ${arraykeys[*]}; do - current=$1"[$index]" - [[ "${!current}" == "$2" ]] && return 0; # found - done - return 1; # not found + if $(isArray $1); then + for index in ${arraykeys[*]}; do + current=$1"[$index]" + [[ "${!current}" == "$2" ]] && return 0; # found + done + return 1; # not found + else + >&2 echo "ERROR: $1 not an array!" + return 2; # not an array + fi +} + +isArray(){ + [[ "$(declare -p $1 2> /dev/null)" =~ "declare -a" ]] && return 0; # is an array + return 1; # not an array } ##