bug-bash
[Top][All Lists]
Advanced

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

Re: bash 5.0 nested array subscript arithmetic expansion error


From: Chet Ramey
Subject: Re: bash 5.0 nested array subscript arithmetic expansion error
Date: Mon, 27 Aug 2018 16:11:47 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 8/27/18 12:25 PM, Grisha Levit wrote:
> This used to work:
> 
> bash-4.4$ a=0
> bash-4.4$ echo $(( a[a[0]] ))
> 0
> bash-4.4$ echo ${a[a[a[0]]]}
> 0
> 
> But is broken in bash-5.0:
> 
> bash-5.0$ a=0
> bash-5.0$ echo ${a[a[a[0]]]}
> bash: a[a[0]]: syntax error: invalid arithmetic operator (error token is "]")
> bash-5.0$ echo $(( a[a[0]] ))
> bash: a[a[0]] : syntax error: invalid arithmetic operator (error token is "] 
> ")

This is part of changes in bash-5.0 to avoid expanding array subscripts
more than one time. After expanding the subscript once, you don't want
to expand (or check) nested open and close brackets again -- how do you
get literal brackets into an associative array key, for instance? I'll take
a look and see if there's an easy way to allow this syntax, which -- you
have to admit -- is fairly obscure.

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/



reply via email to

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