[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test -v difference between bash 5.1 and 5.2
From: |
Kerin Millar |
Subject: |
Re: test -v difference between bash 5.1 and 5.2 |
Date: |
Tue, 29 Aug 2023 16:56:51 +0100 |
On Tue, 29 Aug 2023 11:44:13 -0400
Chet Ramey <chet.ramey@case.edu> wrote:
> On 8/29/23 11:38 AM, Kerin Millar wrote:
> > On Tue, 29 Aug 2023 11:24:43 -0400
> > Chet Ramey <chet.ramey@case.edu> wrote:
> >
> >> If you want to check whether an array variable is set, you can check
> >> whether it has any set elements:
> >>
> >> (( ${#assoc[@]} > 0 ))
> >
> > This doesn't check whether an "array variable is set".
>
> It checks whether there are any set elements. You have to assign a value
> to set a variable.
I conflated the property of being set with that of being declared. Sorry about
that. So, what I really meant to say was that the existing test does not prove
that it's declared. I initially thought that Christian might be concerned with
that distinction, but do hope it's not the case.
>
> > Not only that, but the test will be true in the case that assoc has been
> > defined as a variable that is not an array.
>
> One hopes that the shell programmer knows what variable types he's
> using, and uses the appropriate constructs.
Some elect to source shell code masquerading as configuration data (or are
using programs that elect to do so). Otherwise, yes, definitely.
--
Kerin Millar
Re: test -v difference between bash 5.1 and 5.2, Kerin Millar, 2023/08/29