zsh-users
 help / color / mirror / code / Atom feed
From: Zefram <zefram@fysh.org>
To: phil@psidev.net (Phil Pennock)
Cc: zsh-users@sunsite.auc.dk
Subject: Re: expansion of nested parameters
Date: Mon, 22 Nov 1999 19:34:56 +0000 (GMT)	[thread overview]
Message-ID: <E11pzEm-0007ie-00@crucigera.fysh.org> (raw)
In-Reply-To: <19991122190225.A8613@psidev.net> from Phil Pennock at "Nov 22, 1999  7: 2:25 pm"

Phil Pennock wrote:
>a=foo
>wib_foo_ble=Wow
>c=\$wib_${a}_ble
>print ${(e)c}

>1: Why does the second print statement print out the current process ID
>   from $$ instead of printing the same as the first print statement?

Because you put "$" where it was expecting a parameter name, and "$"
is in fact a valid parameter name.

>2: Is there a way to do this without using an intermediate variable, as
>   I've done with $c and without using eval statements?

Yes.  You can use the form "${:-arbitrary string}" to get a $ expansion
that expands to an arbitrary string.  $ expansions can be used in
the string.  So you want to do

	a=foo
	wib_foo_ble=Wow
	print ${(e):-\$wib_${a}_ble}

This trick is now documented, in zshexpn(1):

#       ${name:-word}
#              If  name is set and is non-null then substitute its
#              value; otherwise substitute word. If name is  miss-
#              ing, substitute word.

-zefram


  reply	other threads:[~1999-11-22 19:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-22 19:02 Phil Pennock
1999-11-22 19:34 ` Zefram [this message]
1999-11-22 20:14 ` 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=E11pzEm-0007ie-00@crucigera.fysh.org \
    --to=zefram@fysh.org \
    --cc=phil@psidev.net \
    --cc=zsh-users@sunsite.auc.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).