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: Ulrich Mueller
Subject: Re: test -v for array does not work as documented
Date: Thu, 20 Feb 2020 13:48:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.60 (gnu/linux)

>>>>> On Wed, 19 Feb 2020, Stephane Chazelas wrote:

> 2020-02-19 17:18:14 +0100, Ulrich Mueller:
> [...]
>> So, is there any syntax that allows to test if a value has been assigned
>> to the array variable? Especially, to distinguish VARNAME=() (empty
>> array) from VARNAME being unset?
> [...]

> You could do:

> if typeset -p var 2> /dev/null | grep -q '='; then
>   echo var has a value
> fi

> [...]

Yes, basically that's what I had suggested as a workaround in the
downstream bug: https://bugs.gentoo.org/710076#c2

Still, I think it's sad that there isn't a command that can test for
assigned vs void variable, without the need for parsing of declare -p
output.



reply via email to

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