Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14542

Re: bash 5.0 nested array subscript arithmetic expansion error

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: bash 5.0 nested array subscript arithmetic expansion error
Date 2018-08-27 16:11 -0400
Message-ID <mailman.13.1535400719.1284.bug-bash@gnu.org> (permalink)
References <CAMu=BrqOB2qztjRmRdiaHDbrVZskEGsWpsyxuRVsUOiLKpAcXg@mail.gmail.com>

Show all headers | View raw


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/

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: bash 5.0 nested array subscript arithmetic expansion error Chet Ramey <chet.ramey@case.edu> - 2018-08-27 16:11 -0400

csiph-web