[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: question about, why does my code work in normal bash but not bash de
From: |
Chet Ramey |
Subject: |
Re: question about, why does my code work in normal bash but not bash devel |
Date: |
Mon, 25 Apr 2022 10:02:27 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 |
On 4/24/22 5:08 PM, alex ratchev wrote:
the mkmenu in the script
and the printf menustr .. it prints a wanted menu by bash 5.1.16 , but on
5.2b from ~ a week ago it prints empty
You're not going to get the variable expansion you want in the subscript:
mkmenu() {
declare var
menustr=
for var in $( compgen -A function ) ; do
[[ -v help[\$var] ]] ||
continue
menustr+="$var <- ${help[$var]}"$'\n'
done
}
because you quoted it too much. This is what this CHANGES entry means:
k. Bash attempts to expand indexed array subscripts only once when executing
shell constructs and word expansions.
though it should say `indexed and associative'. In bash-5.2, bash tries to
behave as if `assoc_expand_once' is set when expanding associative array
subscripts for shell compound commands and parameter expansions. You can
set BASH_COMPAT=51 to get the behavior you want.
There was a pretty spirited discussion about this last year:
https://lists.gnu.org/archive/html/bug-bash/2021-03/msg00056.html
and the bash-5.2 behavior -- which is much safer -- can be reverted with
the compatibility mode.
--
``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/