[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "${assoc[@]@k}" doesn't get expanded to separate words within compou
From: |
Zachary Santer |
Subject: |
Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax |
Date: |
Tue, 19 Mar 2024 23:51:21 -0400 |
On Tue, Mar 19, 2024 at 11:18 PM Zachary Santer <zsanter@gmail.com> wrote:
>
> Repeat-By:
>
> $ declare -A assoc_1=( [key 0]='value 0' [key 1]='value 1' [key
> 2]='value 2' [key 3]='value 3' )
> $ unset assoc_2
> $ declare -A assoc_2
> $ printf '|%s|\n' "${assoc_1[*]@k}"
> |key 2 value 2 key 3 value 3 key 0 value 0 key 1 value 1|
> # All one word. Makes sense.
> $ assoc_2=( "${assoc_1[*]@k}" )
> $ declare -p assoc_2
> declare -A assoc_2=(["key 2 value 2 key 3 value 3 key 0 value 0 key 1
> value 1"]="" )
> # Still makes sense.
> $ printf '|%s|\n' "${assoc_1[@]@k}"
> |key 2|
> |value 2|
> |key 3|
> |value 3|
> |key 0|
> |value 0|
> |key 1|
> |value 1|
> # Got expanded to separate words, like it's supposed to.
> $ assoc_2=( "${assoc_1[@]@k}" )
> $ declare -p assoc_2
> declare -A assoc_2=(["key 2 value 2 key 3 value 3 key 0 value 0 key 1
> value 1"]="" )
> # Here, it did not.
This is specific to the compound assignment syntax for an associative
array, even.
$ unset array_1
$ declare -a array_1
$ array_1=( "${assoc_1[*]@k}" )
$ declare -p array_1
declare -a array_1=([0]="key 2 value 2 key 3 value 3 key 0 value 0 key
1 value 1")
$ array_1=( "${assoc_1[@]@k}" )
$ declare -p array_1
declare -a array_1=([0]="key 2" [1]="value 2" [2]="key 3" [3]="value
3" [4]="key 0" [5]="value 0" [6]="key 1" [7]="value 1")
- "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Zachary Santer, 2024/03/19
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax,
Zachary Santer <=
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Lawrence Velázquez, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Zachary Santer, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, alex xmb sw ratchev, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Léa Gris, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, alex xmb sw ratchev, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Lawrence Velázquez, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Zachary Santer, 2024/03/20
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Chet Ramey, 2024/03/22