[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: No expansions performed while declaring an associative array using a
From: |
felix |
Subject: |
Re: No expansions performed while declaring an associative array using a list of keys and values |
Date: |
Mon, 14 Dec 2020 08:59:59 +0100 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Fri, Dec 11, 2020 at 03:08:04PM +0300, 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)'?
When declaring ``associative array'', I alway use ``quoted'' syntax:
$ foo='1 2'
$ declare -A bar='($foo 3)'
$ declare -p bar
declare -A bar=(["1 2"]="3" )
Not sure how to explain this, but I'm not surprised seeing this working so.
$ bar+=($foo 3)
$ declare -p bar
declare -A bar=(["1 2"]="3" )
Seem ok for me!
--
Félix Hauri - <felix@f-hauri.ch> - http://www.f-hauri.ch
Re: No expansions performed while declaring an associative array using a list of keys and values,
felix <=