Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
easy calling of associative array?
- X-seq: zsh-users 20867
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: easy calling of associative array?
- Date: Sun, 01 Nov 2015 15:12:59 -0800
- 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
test ()
{
eval "baz=\$${1}[key1]"
echo $baz
eval "foo=\$${1}[key2]"
echo $foo
...
}
If I want to pass the name of an associative array to a function via
"$1" and then work with it's keys, the above succeeds but it's sure
laborious. Is there some way to do the eval just once? So that I can
end up doing:
if [ "xyz[key1]" = '1' ]; then ...
... as I experiment, there seems to be no way of replacing 'xyz' with
any expression that will do the job without needing eval's help every
time, but I'll bet there's a way.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author