bug-bash
[Top][All Lists]
Advanced

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

Re: Regression in 5.2 in arithmetic comparison


From: Chet Ramey
Subject: Re: Regression in 5.2 in arithmetic comparison
Date: Thu, 20 Oct 2022 11:48:54 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.3

On 10/18/22 3:55 PM, Glenn Jackman wrote:

Bash Version: 5.2
Patch Level: 0
Release Status: release

Description:
         an arithmetic comparison where an array index contains an array
element fails.

Repeat-By:
         in bash 5.2
                 $ coins[3]=10 i=3 C[5]=42 p=15
                 $ # comparison throws error
                 $ (( C[p - coins[i]] > 10)) && echo Y || echo N
                 bash: p - coins\[i\]: syntax error: invalid arithmetic
operator (error token is "\[i\]")
                 $ # but arithmetic expression is OK
                 $ echo $(( C[p - coins[i]] ))
                 42

Thanks for the report. It's not the array reference that triggers it, but
the arithmetic comparison. If you'd added the comparison to the arithmetic
expansion, you'd have seen the same error.

The cause is the new code in bash-5.2 to prevent multiple evaluation of
array subscripts. The fix is to exempt the presence of `<' and `>' from
that treatment, since they're not treated specially in that context.

I've attached the trivial patch.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: arith-exp-chars.patch
Description: Text document


reply via email to

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