From: Peter Stephenson <pws@ifh.de>
To: Daniel Brahneborg <basic@abalon.se>,
zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: minor bug with ${}
Date: Mon, 23 Sep 1996 10:43:10 +0200 [thread overview]
Message-ID: <199609230843.KAA04141@hydra.ifh.de> (raw)
In-Reply-To: "Daniel Brahneborg"'s message of "Mon, 23 Sep 1996 09:40:03 MET." <199609230740.JAA17818@dolphin.abalon.se>
Daniel Brahneborg wrote:
> This ought to work, but doesn't:
>
> a=b
> b=c
> echo ${a}
> echo ${${a}}
>
> Both echos print 'b', which is wrong.
So called `nested' parameter substitution has actually always been a
bit different to what you would expect. Instead of re-evaluating the
inner substitution as a name, it's simply there to allow you to do
more than one form of special substitution on the same variable. For
example,
echo ${${a:s/b/cd/}#c}
substitutes b to cd then removes the c: it doesn't treat the `cd' as a
variable name.
I've always found this rather counter-intuitive, but it's been there
since one of the early patches posted to the list some five years ago.
A better syntax would have been something like `${{a:s/b/cd/}#c}' to
do the substitution above, with an extra $ doing what you were
expecting. (It's a bit late now, since it would wreck all of Bart's
scripts, yet again :-(.)
Consequently, you need one of the usual circumlocutions with eval,
like
eval echo \${${a}}
--
Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
next prev parent reply other threads:[~1996-09-23 9:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-09-23 7:40 Daniel Brahneborg
1996-09-23 8:43 ` Peter Stephenson [this message]
1996-09-23 11:10 ` Hrvoje Niksic
1996-09-23 20: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=199609230843.KAA04141@hydra.ifh.de \
--to=pws@ifh.de \
--cc=basic@abalon.se \
--cc=zsh-workers@math.gatech.edu \
/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).