[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test -v for array does not work as documented
From: |
Greg Wooledge |
Subject: |
Re: test -v for array does not work as documented |
Date: |
Thu, 20 Feb 2020 10:11:27 -0500 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Thu, Feb 20, 2020 at 04:05:01PM +0100, 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 appears to work very differently at the global scope, compared to
local scope.
wooledg:~$ unset var
wooledg:~$ declare -p var; echo $?
bash: declare: var: not found
1
wooledg:~$ f() { local var=x; unset var; declare -p var; echo $?; }
wooledg:~$ f
declare -- var
0
Intriguing, but everything about this still screams "stop doing this".
Whatever the actual goal is, this isn't the way to reach it.
- 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, 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,
Greg Wooledge <=
- 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