[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash-5.2 Release available
From: |
Greg Wooledge |
Subject: |
Re: Bash-5.2 Release available |
Date: |
Mon, 31 Oct 2022 18:15:42 -0400 |
On Mon, Oct 31, 2022 at 03:00:42PM -0700, Corey Hickey wrote:
> Greg, why do you say this part?
>
> > https://mywiki.wooledge.org/BashPitfalls#pf62
> >
> > As of bash 5.2, the only safe, working way to modify an element of an
> > associative array in a calculation is to make a temporary copy of the
> > value in a regular (string) variable.
>
> I can see that pre/post 5.2 compatibility would be problematic
> without a temporary variable--earlier versions of bash require escaping
> the dollar sign and 5.2 does not give that any special meaning.
>
> Other than forward/backward compatibility, is there some other problem
> with the 5.2 behavior that I am missing? From what I've seen so far, 5.2
> (with Chet's patch) has the least surprising behavior to me (given that
> I consider recursive expansion of array keys to be surprising).
I might not have written it as clearly as possible. Using a temporary
variable to retrieve the associative array element outside of the math
context is the only way that'll work across bash versions without
triggering code injection *or* a key lookup failure.