Re: bash 5.0 nested array subscript arithmetic expansion error

2018-10-17 Thread Dan Douglas
On Wed, Oct 17, 2018 at 9:05 AM Chet Ramey  wrote:
> You know this has already been done, right?

I do now! Still trying to get caught up with the changelog.



Re: bash 5.0 nested array subscript arithmetic expansion error

2018-10-17 Thread Chet Ramey
On 10/16/18 10:10 AM, Dan Douglas wrote:
> On Mon, Aug 27, 2018 at 8:12 PM Chet Ramey  wrote:
>>
>> 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
> 
> Just curious, did you decide what to do with this?

Arithmetic subscript expansion (indexed arrays) will work the same as it
did in bash-4.4.

> If it were a temporary bodge I'd say add a shopt option to disable
> recursive subscript processing in the event someone depends upon weird
> strings in associative arrays. It often isn't a requirement. Too bad
> adding this would probably mean supporting it forever.

You know this has already been done, right?

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



Re: bash 5.0 nested array subscript arithmetic expansion error

2018-10-16 Thread Dan Douglas
On Mon, Aug 27, 2018 at 8:12 PM Chet Ramey  wrote:
>
> 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

Just curious, did you decide what to do with this?

> 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?

By treating associative arrays and ordinary arrays differently.
Associative arrays should be the easier one because any
unescaped/unquoted bracket that isn't part of an expansion is part of
the string.

Integrating arithmetic into the overall Bison/Flex-defined syntax
would be an idealist answer, I guess. Not an easy fix.

Or, have the arithmetic processor stop whenever it encounters var[,
Hand the remainder of the current command back to the shell parser or
length into the expression where the expansion begins to figure out
its extent. Return the length to the end of the expansion plus the
expanded string, seek ahead, resume.

Or, re-use the code already used in contexts processing expansions on
arbitrary strings, such as the argument to case..esac. Arithmetic
doesn't contain tokens that start expansions so there's no need for
the shell to understand it. Just find the unescaped $'s (and
backticks, ugh), expand them, and tell the math processor their
locations and value. Ignoring ] on expanded strings of course.

If it were a temporary bodge I'd say add a shopt option to disable
recursive subscript processing in the event someone depends upon weird
strings in associative arrays. It often isn't a requirement. Too bad
adding this would probably mean supporting it forever.

> 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.

I can live with broken associative arrays a bit longer if it means
time to come up with a better solution.



Re: bash 5.0 nested array subscript arithmetic expansion error

2018-08-27 Thread Chet Ramey
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, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



bash 5.0 nested array subscript arithmetic expansion error

2018-08-27 Thread Grisha Levit
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 "] ")