From: Cosmo <cosmo@uk.ibm.com>
To: Omen Wild <Omen.Wild@Dartmouth.EDU>
Cc: zsh users <zsh-users@sunsite.dk>
Subject: Re: Build a variable name from another variable?
Date: Fri, 23 Jan 2004 23:47:43 +0000 [thread overview]
Message-ID: <4011B29F.8040304@uk.ibm.com> (raw)
In-Reply-To: <20040123224220.GB3354@descolada.dartmouth.edu>
Omen Wild wrote:
>
>
>
> I am not totally sure what it is called, but I want to build a variable
> name dynamically, from the contents of another variable. That is, I
> have:
>
> ----- Begin script -----
> barcontents="bar contents"
> baz="bar"
>
> echo $barcontents # <---- effect I want
> echo ${${baz}contents} # <---- how I want to get there
> ----- End script -----
>
> I get this error: bad substitution
>
> I think the answer involves the (P) flag, as in:
> echo ${${(P)baz}contents}
Back in the old days, before these fancy complicated shells, I'd just do this:
eval echo \$${baz}contents
;-)
Cosmo
prev parent reply other threads:[~2004-01-24 0:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-23 22:42 Omen Wild
2004-01-23 23:19 ` Philippe Troin
2004-01-24 0:51 ` Omen Wild
2004-01-24 2:36 ` Bart Schaefer
2004-01-23 23:47 ` Cosmo [this message]
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=4011B29F.8040304@uk.ibm.com \
--to=cosmo@uk.ibm.com \
--cc=Omen.Wild@Dartmouth.EDU \
--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).