* eval "echo \"$a=( \${(qq)$a[@]} )\""
@ 2016-02-14 17:16 Sebastian Gniazdowski
2016-02-14 19:01 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2016-02-14 17:16 UTC (permalink / raw)
To: Zsh Users
Hello,
say "a" holds array name "arr". Doing:
% a=arr; arr=( a b "c d" ); eval "echo \"$a=( \${(qq)$a[@]} )\""
yields:
arr=( 'a b c d' )
And it should be:
% k=arr; arr=( a b "c d" ); declline=`declare -p ${(q)k}`; echo
"$k=${declline#*=}"
arr=( a b 'c d' )
I would use the declare-output-catching way but no output is given for
"-hide-" (in (t)) variables. Maybe a workaround specifically to this?
How to accomplish what's needed? Printing array elements with correct
quoting, having indirect reference to the array – its name.
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: eval "echo \"$a=( \${(qq)$a[@]} )\""
2016-02-14 17:16 eval "echo \"$a=( \${(qq)$a[@]} )\"" Sebastian Gniazdowski
@ 2016-02-14 19:01 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2016-02-14 19:01 UTC (permalink / raw)
To: Zsh Users
On Feb 14, 6:16pm, Sebastian Gniazdowski wrote:
} Subject: eval "echo \"$a=( \${(qq)$a[@]} )\""
}
} say "a" holds array name "arr".
This is the reason ${(P)a} exists.
It wasn't fully functional for associative arrays until quite recently.
} Doing:
}
} % a=arr; arr=( a b "c d" ); eval "echo \"$a=( \${(qq)$a[@]} )\""
The [@] is being applied to $a, not to the expansion into "arr".
You meant (note one extra set of braces):
% a=arr; arr=( a b "c d" ); eval "echo \"$a=( \${(qq)${a}[@]} )\""
arr=( 'a' 'b' 'c d' )
But all you really need is
% echo $a=\(${(kvqqP)a}\)
arr=('a' 'b' 'c d')
For an associative array that works only in zsh-5.2 and later, but it
otherwise works for both associative and indexed arrays (the kv is just
ignored in the indexed case).
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-14 19:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-14 17:16 eval "echo \"$a=( \${(qq)$a[@]} )\"" Sebastian Gniazdowski
2016-02-14 19:01 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).