[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: |
Greg Wooledge |
Subject: |
Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax |
Date: |
Sun, 24 Mar 2024 15:05:40 -0400 |
On Sun, Mar 24, 2024 at 07:46:46PM +0200, Oğuz wrote:
> On Sunday, March 24, 2024, Zachary Santer <zsanter@gmail.com> wrote:
> >
> > Yeah, but what can you do with @k?
>
>
> It helps when reconstructing an associative array as a JSON object in JQ
>
> $ declare -A a=([x]=1 [y]=2)
> $ jq --args -n '[$ARGS.positional | _nwise(2) | {(.[0]): .[1]}] | add'
> "${a[@]@k}"
> {
> "y": "2",
> "x": "1"
> }
Conceptually that looks great, but how do you avoid "Argument list
too long" with larger inputs?
I've got this example on hand, but it doesn't include a hash:
hobbit:~$ a=("an array" "of strings"); b="a string"; printf '%s\0' "${a[@]}" |
jq -R --arg b "$b" '{list: split("\u0000"), string: $b}'
{
"list": [
"an array",
"of strings"
],
"string": "a string"
}
- 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, 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
- 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, 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 <=
- 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