[Top][All Lists]

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

@K transformation

From: Ilkka Virta
Subject: @K transformation
Date: Thu, 19 Aug 2021 12:15:52 +0300

On Thu, Aug 19, 2021 at 5:49 AM Koichi Murase <myoga.murase@gmail.com>

> FYI, zsh provides this feature for associative arrays with the syntax
> ${(kv)assoc} or ${(@kv)assoc}. Note that Bash-5.1 already has a
> similar feature ${array[@]@K}, but the substitution result is quoted
> so cannot be directly used for the present purpose.

 $ declare -A A=([foo bar]="123 456" [adsf]="456 789")
$ printf "<%s>\n" "${A[@]@K}"
<adsf "456 789" "foo bar" "123 456" >

Interesting. I wonder, what's the intended use-case for this?

The impression I have is that it's easier to turn a list of multiple words
into one
string (e.g. for display purposes), but much harder to keep things as
words (for pretty much anything else). So this seems to have a somewhat
usefulness. I can see "${A[*]@K}" producing a single string like that, but
the same
with [@] seems odd compared to how [@] expansions otherwise work.

reply via email to

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