bug-bash
[Top][All Lists]
Advanced

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

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context


From: Martin D Kealey
Subject: Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context
Date: Mon, 22 May 2023 19:57:43 +1000

On Mon, 22 May 2023, 12:59 Emanuele Torre, <torreemanuele6@gmail.com> wrote:

> I am not really proposing a major change to the behaviour of nounset, I
> am only pointing out the incorrect bash behaviour for that case.


I disagree: this would constitute a major change, breaking behaviour that
is (for good reasons) depended on.

It's my opinion that the current behaviour is "working as intended" and
doesn't need fixing. It's not perfect but it's better than the alternatives.

There's no parallel with "misspelt variable name", since it's unlikely that
referencing an unset array slot constitutes a programmer typo.

Rather it's more in the nature of a potential logic error; or may in fact
be working exactly as intended.

It may be tempting to suggest that we could "be explicit" and change "a[x]"
to "${a[x]-0}" in numeric context.

I think that cure would be worse than the disease, because it has
undesirable hidden effects on operator precedence and order of evaluation.

-Martin


reply via email to

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