On Mon, Jun 30, 2025 at 1:45 PM Robert Elz <k...@munnari.oz.au> wrote:
>
> What's more, I don't see what the issue is, inside (( )) or $(( ))
> is what should be treated as a double quoted string (arith context
> for evaluation, but still a double quoted string - and the first thing
> the shell should be doing with any double quoted string, in any context,
> is to do any var/cmdsub/arith expansions that occur within it.   Then
> it gets used for whatever purpose it has.

I understand this as an attempt to resolve Bash Pitfalls 45 and 62.

https://mywiki.wooledge.org/BashPitfalls#A.28.28_hash.5B.24key.5D.2B-.2B-_.29.29
It appears bash has made the parser more complex by selectively
removing the pre-expansion step for certain parts of expressions.
That's bad because the rules for when that happens are undocumented
[...]

It seems like the pre-expansion step could be removed for only what
appears between [ and ] in arithmetic contexts and you'd have what you
need. At whatever later stage where bash knows if it's dealing with an
indexed or an associative array element, that content itself could be
evaluated in an arithmetic context or not.

You need to do something complex like this, or an associative array
key like ']' showing up in a parameter expansion is going to cause a
syntax error when the overall (( )) arithmetic context is being
evaluated.

> Do that in the given example, and
>
>         ((i=$x,a[b[i]]))
> turns into
>         ((i=0,a[b[i]]))
>
> which does work.    Of course, I know nothing about how any of this
> is implemented inside bash, but this just seems simple to me, and
> if as:
>
>
> chet.ra...@case.edu said:
>   | This was one of the results of this 2021 discussion:
>   | https://lists.gnu.org/archive/html/bug-bash/2021-03/msg00056.html
>   | You can get the result you want by not using the $.
>
> then something went very badly wrong with what happened there, and
> simply saying "don't use the $" is not nearly good enough.

Yeah, that makes it sound like the second bash's parser encounters a $
anywhere within (( )), it changes how the entire expression is
evaluated. That seems like a poor approach to take.

Reply via email to