On Wed, Feb 19, 2020 at 11:38 AM Ulrich Mueller <u...@gentoo.org> 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