On Wed, Jul 27, 2016 at 09:06:50AM +0300, Pierre Gaston wrote:
[...]
> > Description:
> >         Unlike usual variables, that have been assigned an empty value,
> > arrays are treated by test -v as if they weren’t assigned anything.
[...]
> > This has been reported and discussed several times.
> bash consider an array as unset until at least one of its element has been
> assigned a value.

I would rephrase that, since test -v arrname will return true only if the
zero element is set

|    dualbus@hp:~$ a=([1]=1 [2]=2); declare -p a
|    declare -a a='([1]="1" [2]="2")'
|    dualbus@hp:~$ test -v a
|    dualbus@hp:~$ echo $?
|    1
|
|    dualbus@hp:~$ a=([0]=0 [1]=1 [2]=2); declare -p a
|    declare -a a='([0]="0" [1]="1" [2]="2")'
|    dualbus@hp:~$ test -v a
|    dualbus@hp:~$ echo $?
|    0

Examples of previous discussion:

- https://lists.gnu.org/archive/html/bug-bash/2014-11/msg00099.html
- https://lists.gnu.org/archive/html/bug-bash/2015-04/msg00094.html

-- 
Eduardo Bustamante
https://dualbus.me/

Reply via email to