bug-bash
[Top][All Lists]
Advanced

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

Re: nounset option: Error message points to the wrong variable when acce


From: alex xmb ratchev
Subject: Re: nounset option: Error message points to the wrong variable when accessing associative arrays
Date: Wed, 10 May 2023 20:50:35 +0200

On Wed, May 10, 2023, 19:45 Baumann, Moritz <moritz.baumann@sap.com> wrote:

> > Anyway, that is still correct behaviour; the reason why that happens is
> > that when you assign you perform an array expansion on a variable that
> > is neither a -a nor a -A variable, the variable is treated as a -a
> > (indexed array) variable.
>
> Thank you for the explanation. I was immediately wondering about the reason
> for the unfortunate order of evaluation, but you covered that, too:
>
> > Also note that  nounset  does not report errors if you expand an array
> > variable that is not set with @, or a [@]:start:length PE that does not
> > have values, that is why the subscript is evaluated first.
>
> So, the error message might be extremely confusing, but it cannot be fixed.
>
> In the case that lead me to submit this report, the error even occurred
> inside a check for the existence of an array key, which made the resulting
> message even weirder:
>
> if [[ -v "mistyped_array[$1]" ]]; then
>   ...
> fi
>

[[ -v arr[\$var] ]]

Anyway, thank you for the detailed reply and sorry for the bogus report.
>
> Best regards,
> Moritz Baumann
>
>


reply via email to

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