[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: |
Sun, 24 Mar 2024 13:04:38 -0400 |
On Fri, Mar 22, 2024 at 11:23 AM Chet Ramey <chet.ramey@case.edu> wrote:
>
> This is what you can do with @K.
>
> https://lists.gnu.org/archive/html/bug-bash/2021-08/msg00119.html
>
> Word splitting doesn't happen on the rhs of an assignment statement, so you
> use eval. The @K quoting is eval-safe.
Yeah, but what can you do with @k?
$ unset assoc array assoc_copy
$ declare -A assoc=( [zero]=0 [one]=1 [two]=2 )
$ declare -a array=( "${assoc[@]@k}" )
$ eval "declare -A assoc_copy=( ${assoc[*]@K} )"
$ declare -p assoc array assoc_copy
declare -A assoc=([two]="2" [one]="1" [zero]="0" )
declare -a array=([0]="two" [1]="2" [2]="one" [3]="1" [4]="zero" [5]="0")
declare -A assoc_copy=([two]="2" [one]="1" [zero]="0" )
The difference in expansion behavior between indexed and associative
array compound assignment statements doesn't make sense. As nice as it
is to have expansions that expand to eval-safe expressions, needing
eval less would be nicer.
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, (continued)
- 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
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/22
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Lawrence Velázquez, 2024/03/22
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/22
- 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, Oğuz, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Oğuz, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Oğuz, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Lawrence Velázquez, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Dennis Williamson, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Greg Wooledge, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Dennis Williamson, 2024/03/24
- Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax, Chet Ramey, 2024/03/25