Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15933

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

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: test -v for array does not work as documented
Date 2020-02-20 14:37 -0500
Message-ID <mailman.1282.1582227461.2412.bug-bash@gnu.org> (permalink)
References <mailman.4206.1582208094.2410.bug-bash@gnu.org> <w6gh7zlz4de.fsf@kph.uni-mainz.de> <a07dd152-b50a-a77b-13c1-fc559b053fdd@case.edu>

Show all headers | View raw


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.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: test -v for array does not work as documented Chet Ramey <chet.ramey@case.edu> - 2020-02-20 14:37 -0500

csiph-web