bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'mapfile -O1 array' breaks '[[ -v array ]]'


From: Greg Wooledge
Subject: Re: 'mapfile -O1 array' breaks '[[ -v array ]]'
Date: Mon, 17 Apr 2023 13:38:20 -0400

On Mon, Apr 17, 2023 at 10:23:17AM -0700, Wiley Young wrote:
> Description:
>         When an array 'a_foo' is created with 'mapfile -d '' -t', it is
> tested with '[[ -v a_foo ]]' and '[[' returns 0. When '-O 1' is added to
> mapfile, '[[ -v a_foo ]]' returns non-0.

It's not specifically the -O1 option.  It's the fact that there's no
element 0.

unicorn:~$ unset a
unicorn:~$ a[1]=foo
unicorn:~$ [[ -v a ]]; echo "$?"
1

I believe [[ -v a ]] is equivalent to [[ -v a[0] ]].

I have never yet seen a justifiable reason to use [[ -v ]].  All I've
ever seen come out of it are bugs and confusion.



reply via email to

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