Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expansion of nested parameters
- X-seq: zsh-users 2744
- From: Zefram <zefram@xxxxxxxx>
- To: phil@xxxxxxxxxx (Phil Pennock)
- Subject: Re: expansion of nested parameters
- Date: Mon, 22 Nov 1999 19:34:56 +0000 (GMT)
- Cc: zsh-users@xxxxxxxxxxxxxx
- In-reply-to: <19991122190225.A8613@xxxxxxxxxx> from Phil Pennock at "Nov 22, 1999  7: 2:25 pm"
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author