maybe implent a shopt -s no_expand_subshells

On Thu, Mar 11, 2021 at 9:20 PM Chet Ramey <chet.ra...@case.edu> wrote:

> On 3/11/21 10:06 AM, Jason A. Donenfeld wrote:
> > This behavior is quite surprising:
>
> The idea is that array subscripts undergo a uniform set of expansions when
> they're used, no matter the context. Builtins already undergo word
> expansions as part of command execution. The result is double expansion
> in certain cases (there are more; this is a staple of discussion here on
> the list).
>
> You can use the `assoc_expand_once' shell option to reduce the number of
> expansions; it would have prevented the behavior you observed here, for
> instance. But it's not perfect, as many people on the list will tell you.
>
> >
> > $ declare -A blah
> > $ blah['$(DOESNOTEXIST)']=broken
> > $ for i in "${!blah[@]}"; do echo "$i"; done
> > $(DOESNOTEXIST)
> > $ for i in "${!blah[@]}"; do unset blah["$i"]; done
> > bash: DOESNOTEXIST: command not found
> > bash: unset: [$(DOESNOTEXIST)]: bad array subscript
>
>
> $ cat x1
> declare -A blah
> blah['$(DOESNOTEXIST)']=broken
> shopt -s assoc_expand_once
> for i in "${!blah[@]}"; do unset blah["$i"]; done
> declare -p blah
> $ ../bash-5.1-patched/bash ./x1
> declare -A blah=()
>
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/
>
>

Reply via email to