From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh users <zsh-users@sunsite.dk>
Subject: Re: help with dereferencing variables
Date: Sat, 14 Feb 2004 21:24:00 +0000 [thread overview]
Message-ID: <1040214212400.ZM15293@candle.brasslantern.com> (raw)
In-Reply-To: <200402140959.24015.scowles@earthlink.net>
On Feb 14, 9:59am, S. Cowles wrote:
}
} In the following code, method 1 gives the expected results. Method
} 2, however, breaks with the error: unknown file attribute. Is the
} eval in Method 1 required, or is there a correct syntax to make the
} dereference occur in Method 2 without an eval?
The short answers are "not precisely" and "no".
} # method 1:
} b=$(echo "${key}=( ${(@)${(P)val}} )")
} eval $b
You don't need the $(echo) and the assignment to $b here. It should be
enough to do
eval ${key}'=( ${(P)val} )'
(note placement of single quotes).
} # method 2:
} ${key}=( ${(@)${(P)${val}}} )
This syntax is not an assignment, because the stuff to the left of the
equals sign is not an identifier name. (This used to work in older
versions of zsh because the variable was expanded before zsh looked
for assignment syntax, but that was incompatible with other shells.)
Even if this were an assignment, The ${(@)...} is extraneous when the
whole thing is not in double quotes. And you don't need ${(P)${val}},
just ${(P)val} is enough.
next prev parent reply other threads:[~2004-02-14 21:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-14 17:59 S. Cowles
2004-02-14 21:24 ` Bart Schaefer [this message]
2004-02-15 4:12 ` S. Cowles
2004-02-15 17:04 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1040214212400.ZM15293@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).