Bash -v test doesn't work with associative arrays in 4.3.46
4
votes
2
answers
1129
views
The
-v
unary operator that was introduced in version 4.2 to test if a variable is set or not does not appear to work in bash 4.3.46 on associative arrays.
I have some bash test code that I run against a set of bash functions, and they all pass in bash 4.2 (on CentOS 7.1). I recently booted up a Lubuntu 16.04.1 distro and noticed a good portion of my tests now failed, with bash 4.3.46. It seems like all of the failures are due to code like this:
function is_var_set {
local var="${1:?"No var provided to 'is_var_set'!"}"
[[ -v "$var" ]]
}
declare -A array=(["a"]="element 1")
is_var_set "array"
Is this a widely known thing/was support removed for associative arrays?
Asked by krb686
(559 rep)
Nov 7, 2016, 12:16 AM
Last activity: Jan 1, 2022, 04:43 PM
Last activity: Jan 1, 2022, 04:43 PM