On Wed, Nov 19, 2014 at 04:20:51PM +0000, Jason Vas Dias wrote: > Good day - > Please could anyone explain why the first command below produces no output: > $ ( declare -A a=([a]=1); if [ -v a ]; then echo yes; fi ) > $ ( declare -a a=([0]=1); if [ -v a ]; then echo yes; fi ) > yes
In a lot of places, when you use the name of an array without an index, Bash assumes you mean index 0. imadev:~$ unset a; declare -a a=([1]=1); test -v a && echo yes imadev:~$ unset a; declare -A a=([0]=1); test -v a && echo yes yes So it's not indexed vs. associative arrays. It's simply the fact that you used index a instead of index 0, plus the fact that -v a is really -v 'a[0]'. Does this make -v unusable for arrays? Possibly.