On 12/11/20 7:08 AM, Oğuz wrote:
I was trying the new features of bash 5.1 and came across this inconsistent
behavior:
$ foo='1 2'
$ declare -A bar=($foo 3)
$ declare -p bar
declare -A bar=(["\$foo"]="3" )
$
$ bar+=($foo 3)
$ declare -p bar
declare -A bar=(["\$foo"]="3" ["1 2"]="3" )
Is there a particular reason to avoid performing expansions in `declare -A
bar=($foo 3)'?
The idea is that each word in the list undergoes the same expansion as the
keys and values in a [$key]=value word in the compound assignments. Right
now, the implementation is pretty simple. For instance, if you use
something like
set -- a b c d e f g
declare -A v
v=( "$@" )
you'll get an associative array with a single key 'a b c d e f g' and a
null value.
I agree that it would be useful to have
foo='1 2'
declare -A v1=$( $foo 3 )
declare -A v2=$( [$foo]=3 )
set the two arrays to the same contents, so I'll see what needs to change
to do that.
Chet
--
``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/