zsh-workers
 help / color / mirror / code / Atom feed
* minor bug with ${}
@ 1996-09-23  7:40 Daniel Brahneborg
  1996-09-23  8:43 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Brahneborg @ 1996-09-23  7:40 UTC (permalink / raw)
  To: zsh-workers; +Cc: Daniel Brahneborg

Hi.

There is a small bug with nestled ${} in Zsh 3.0.0.
This ought to work, but doesn't:

a=b
b=c
echo ${a}
echo ${${a}}

Both echos print 'b', which is wrong.
It behaves the same on all platforms.

I'm not a member of this list, so keep me on the Cc: line.

\Basic


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: minor bug with ${}
  1996-09-23  7:40 minor bug with ${} Daniel Brahneborg
@ 1996-09-23  8:43 ` Peter Stephenson
  1996-09-23 11:10   ` Hrvoje Niksic
  1996-09-23 20:04   ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Stephenson @ 1996-09-23  8:43 UTC (permalink / raw)
  To: Daniel Brahneborg, Zsh hackers list

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: minor bug with ${}
  1996-09-23  8:43 ` Peter Stephenson
@ 1996-09-23 11:10   ` Hrvoje Niksic
  1996-09-23 20:04   ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Hrvoje Niksic @ 1996-09-23 11:10 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Daniel Brahneborg, Zsh hackers list

Peter Stephenson (pws@ifh.de) wrote:
> Consequently, you need one of the usual circumlocutions with eval,
> like
> eval echo \${${a}}

The same holds true for sh, bash and ksh. Neither of them support
${${a}}.

-- 
hniksic@srce.hr              |  Student of electrical engineering
hniksic@fly.cc.fer.hr        |  University of Zagreb, Croatia
------------------------------------------------------------------
I'm a Lisp variable -- bind me!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: minor bug with ${}
  1996-09-23  8:43 ` Peter Stephenson
  1996-09-23 11:10   ` Hrvoje Niksic
@ 1996-09-23 20:04   ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 1996-09-23 20:04 UTC (permalink / raw)
  To: Peter Stephenson, Zsh hackers list

On Sep 23, 10:43am, Peter Stephenson wrote:
} Subject: Re: minor bug with ${}
}
} 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 :-(.)

Chuckle.  Actually, I don't use "nested" substitution very much.  It's
only in the last few months that I've started replacing some constructs
that required external "sed"s etc. with some of this stuff.

I'm just as opposed to breaking other people's scripts, though. :-}

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-09-23 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-23  7:40 minor bug with ${} Daniel Brahneborg
1996-09-23  8:43 ` Peter Stephenson
1996-09-23 11:10   ` Hrvoje Niksic
1996-09-23 20:04   ` Bart Schaefer

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).