Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expansion of nested parameters
- X-seq: zsh-users 2745
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: Phil Pennock <phil@xxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxxxxxxxxx>
- Subject: Re: expansion of nested parameters
- Date: Mon, 22 Nov 1999 20:14:53 +0000
- In-reply-to: <19991122190225.A8613@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <19991122190225.A8613@xxxxxxxxxx>
On Nov 22, 7:02pm, Phil Pennock wrote:
} Subject: expansion of nested parameters
}
} This is with zsh-3.0.7:
} -----------------------------< cut here >-------------------------------
} #!/bin/zsh -f
} a=foo
} wib_foo_ble=Wow
} c=\$wib_${a}_ble
} print ${(e)c}
} print ${(e)\$wib_${a}_ble}
} -----------------------------< cut here >-------------------------------
}
} 1: Why does the second print statement print out the current process ID
} from $$ instead of printing the same as the first print statement?
${(e)c} means: Expand ${c}, then apply command substitution etc. to the
result of that expansion.
Hence ${(e)\$wib_${a}_ble} means: Expand ${\$wib_${a}_ble}, then ...
You'll note that ${\$} is the same as ${$} because the command-line parser
strips the backslash before the parameter-name interpreter ever gets around
to looking at it. ${$} is the same as $$; the rest of the "wib_${a}_ble"
stuff is simply ignored once zsh recognizes $$.
} 2: Is there a way to do this without using an intermediate variable, as
} I've done with $c and without using eval statements?
Yeah; it's in the FAQ, question 3.22. What you're asking is a variation:
print ${(e)a:+\$wib_${a}_ble}
should do it.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author