bug-bash
[Top][All Lists]
Advanced

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

Re: No expansions performed while declaring an associative array using a


From: Léa Gris
Subject: Re: No expansions performed while declaring an associative array using a list of keys and values
Date: Fri, 11 Dec 2020 14:14:27 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 11/12/2020 à 13:08, Oğuz écrivait :
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)'?

Oğuz


Look like coherent with other Bash specific constructs like previous associative array key syntax that does not split a key variable:

    foo='1 2'
    declare -A bar=([$foo]=3 )

Or double square bracket tests:

    foo='1 2'
    [[ $foo == '1 2' ]]

Did you try with?:

    # possibly originating read -a or mapfile
    declare -a foo=(1 2 )

    # Declare associative array from key value array above
    declare -A assoc=("${foo[@]}" 3)

--
Léa Gris




reply via email to

[Prev in Thread] Current Thread [Next in Thread]