bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: test -v for array does not work as documented


From: Grisha Levit
Subject: Re: test -v for array does not work as documented
Date: Wed, 19 Feb 2020 16:26:35 -0500

On Wed, Feb 19, 2020 at 11:38 AM Ulrich Mueller <address@hidden> wrote:
> Especially, to distinguish VARNAME=() (empty
> array) from VARNAME being unset?

I'm not sure if it's intended to work this way, but ${var@a} will
report the attributes if the variable has any set, even if it does not
have a value, like:

    [[ ${var@a} == *a* ]] && echo is a declared array

This works even for namerefs and indirect references to the variable, like:

    $ var=(); declare -n ref=var; echo ${ref@a}
    a
    $ var=(); ind=var; ${!ind@a}
    a

However, if nounset is enabled, the latter two will trip the "unbound
variable" error while using ${var@a} directly will not.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]