[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 <ulm@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.
- test -v for array does not work as documented, Ulrich Mueller, 2020/02/19
- Re: test -v for array does not work as documented, Chet Ramey, 2020/02/19
- Re: test -v for array does not work as documented, Ulrich Mueller, 2020/02/19
- Re: test -v for array does not work as documented, Chet Ramey, 2020/02/19
- Re: test -v for array does not work as documented, pepa65, 2020/02/19
- Re: test -v for array does not work as documented, Stephane Chazelas, 2020/02/19
- Re: test -v for array does not work as documented, Ulrich Mueller, 2020/02/20
- Re: test -v for array does not work as documented, pepa65, 2020/02/20
- Re: test -v for array does not work as documented,
Grisha Levit <=
- Re: test -v for array does not work as documented, Ulrich Mueller, 2020/02/20
- Re: test -v for array does not work as documented, Greg Wooledge, 2020/02/20
- Re: test -v for array does not work as documented, Chet Ramey, 2020/02/20
- Re: test -v for array does not work as documented, Ulrich Mueller, 2020/02/21
- Re: test -v for array does not work as documented, pepa65, 2020/02/21
- Re: test -v for array does not work as documented, Chet Ramey, 2020/02/23
- Re: test -v for array does not work as documented, pepa65, 2020/02/23
- Re: test -v for array does not work as documented, Chet Ramey, 2020/02/23