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: Fri, 21 Feb 2020 07:20:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.60 (gnu/linux)

>>>>> On Thu, 20 Feb 2020, Chet Ramey wrote:

> On 2/20/20 10:05 AM, Ulrich Mueller wrote:
>>>>>>> On Thu, 20 Feb 2020, pepa65 wrote:
>> 
>>> On 20/02/2020 19.48, Ulrich Mueller wrote:
>>>> 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.
>> 
>>> There is no need to parse, the return value of `declare -p var` or
>>> `typeset -p var` will tell you what you want.
>> 
>> Unfortunately, it doesn't:
>> 
>> $ f() {
>> >   local var
>> >   var="foo"
>> >   declare -p var
>> >   echo $?
>> >   unset var
>> >   declare -p var
>> >   echo $?
>> > }
>> $ f
>> declare -- var="foo"
>> 0
>> declare -- var
>> 0

> It's unset because it doesn't have a value, but it retains the `local'
> attribute so it stays local if subsequently assigned one.

No objections about that. I was just saying that testing the return
status of declare -p is not enough. To find out if a variable is set
or unset, the output must be parsed, e.g., for presense of the = sign.



reply via email to

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