bug-bash
[Top][All Lists]
Advanced

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

Re: Changing the way bash expands associative array subscripts


From: Chet Ramey
Subject: Re: Changing the way bash expands associative array subscripts
Date: Tue, 11 May 2021 10:26:59 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1

On 3/15/21 8:12 PM, Chet Ramey wrote:
I'm kicking around a change to associative array subscript expansion that
would basically force the equivalent of `assoc_expand_once' on all the
time, with additional changes to prevent unwanted double expansion in an
arithmetic expression context. The option would still exist, and still be
settable and unsettable, but have little to no effect in default mode.

For instance,

declare -A assoc
key='x],b[$(echo uname >&2)'

(( assoc[$key]++ ))
declare -p assoc

would display

declare -A assoc=(["x],b[\$(echo uname >&2)"]="1" )

This is relatively straightforward to explain to people.

It's also pretty straightforward to do for internal shell commands and
expansions: things like expression evaluation as part of word expansion,
arithmetic commands, conditional commands, and so on.

The latest push to the devel branch implements this.

It doesn't do anything with the shell builtins yet, beyond allowing
assignment to `*' and `@' associative array keys.

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]