Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: eval "echo \"$a=( \${(qq)$a[@]} )\""
- X-seq: zsh-users 21287
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: eval "echo \"$a=( \${(qq)$a[@]} )\""
- Date: Sun, 14 Feb 2016 11:01:40 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=4cLpfe+0Zdbmmx/deO7ElZ+3Ull9H/h+XkQkgho3CYQ=; b=UURyeHz/NHHLfF9FH1dCOX8Re7nt37daOaL4W8XLh0FtLtkezyeeHN41YsrbXXcSSv Io4x+xQfrcYKzQxBK/wTeEUAM98BMwbzCKVE0s+JqNreF6B0LWRfHyN5pm/PJ7BAf0aO StCTIC51cma1T860TYBLApdL+SOZmpHa9YwmSEq4whMUVPMyZPyPRGWDuMVWeEQhrj2s pvd6KiwRBvOXSXugB0a5cEFULh+wrHx/YZhZPY8aVNLaRegD2GbdrB517CXfuiwDg+GZ I3n2Wm5zsJzZccBdVsR7TuC7Q7ol7iMmUgkdo8V0Ka61JBzpSvY9abEVGbyUxQJSdsYg pWVw==
- In-reply-to: <CAKc7PVDJPVa+AdJfesOUJ1pE5bcjaD2yD1w8kPDiSQ4-VVKaMA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVDJPVa+AdJfesOUJ1pE5bcjaD2yD1w8kPDiSQ4-VVKaMA@mail.gmail.com>
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).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author