From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id TAA29313 for ; Mon, 23 Sep 1996 19:01:19 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id EAA03809; Mon, 23 Sep 1996 04:44:23 -0400 (EDT) Resent-Date: Mon, 23 Sep 1996 04:44:23 -0400 (EDT) Message-Id: <199609230843.KAA04141@hydra.ifh.de> X-Authentication-Warning: hydra.ifh.de: Host pws@localhost didn't use HELO protocol To: Daniel Brahneborg , zsh-workers@math.gatech.edu (Zsh hackers list) Subject: Re: minor bug with ${} In-reply-to: "Daniel Brahneborg"'s message of "Mon, 23 Sep 1996 09:40:03 MET." <199609230740.JAA17818@dolphin.abalon.se> Date: Mon, 23 Sep 1996 10:43:10 +0200 From: Peter Stephenson Resent-Message-ID: <"QEdyo.0.Rx.ctaHo"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2156 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 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.