Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: x86_64-pc-linux-gnu-gcc Compilation CFLAGS: -march=native -ggdb -O2 -pipe -Wno-parentheses -Wno-format-security uname output: Linux a1i15 4.19.102-gentoo #1 SMP Fri Feb 7 14:32:53 CET 2020 x86_64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz GenuineIntel GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.0 Patch Level: 16 Release Status: release Description: The GNU Bash Reference Manual Version 5.0 says about test -v: '-v VARNAME' True if the shell variable VARNAME is set (has been assigned a value). However, it doesn't always return true when VARNAME is an (indexed or associative) array that has been assigned a value. See also Gentoo bug https://bugs.gentoo.org/710076 for some context and additional examples. Repeat-By: $ var1=() $ var2[1]=a $ var3=( b c ) $ declare -A var4; var4["foo"]=d $ declare -p var0 var1 var2 var3 var4 bash: declare: var0: not found declare -a var1=() declare -a var2=([1]="a") declare -a var3=([0]="b" [1]="c") declare -A var4=([foo]="d" ) $ [[ -v var0 ]]; echo $? 1 $ [[ -v var1 ]]; echo $? 1 $ [[ -v var2 ]]; echo $? 1 $ [[ -v var3 ]]; echo $? 0 $ [[ -v var4 ]]; echo $? 1 I would expect 1 only for var0, but 0 for all the others (which have been assigned a value). In fact, bash version 4.2.53 behaves as expected, whereas I get the above result with versions 4.4.23 and 5.0.16.