Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Assign to parameter in parameter -- opposite of ${(P)name}?
- X-seq: zsh-users 15158
- From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Assign to parameter in parameter -- opposite of ${(P)name}?
- Date: Sat, 10 Jul 2010 11:52:48 -0400 (EDT)
- In-reply-to: <20100710145728.GK3043@xxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <alpine.LNX.2.01.1007091908420.4808@xxxxxxxxxxx> <20100710145728.GK3043@xxxxxxxxx>
On Sat, 10 Jul 2010, Julius Plenz wrote:
> Hi, Benjamin!
>
> * Benjamin R. Haskell [2010-07-10 01:35]:
> > but how do you *assign* to a parameter whose name is in a parameter?
>
> > name=foo
> > : ${${(P)name}::=something}
> > echo $foo
> > # should echo 'something'
>
> How about:
>
> zsh> name=foo
> zsh> typeset $name=something
> zsh> echo $foo
> something
Thanks. That'll do. I often need the flexibility of the ${name=value}
and ${name:=value} constructs, but not in this case.
Also, I tended to shy away from defining things via typeset, because it
echoes their values if already set. I didn't realize until just now
rereading the man page that TYPESET_SILENT exists. And I didn't realize
until just testing it that an explicit assignment disables the echo.
The usual case where this bites me is when I try to localize a variable
that I used outside a function.
--
Thanks,
Ben
Messages sorted by:
Reverse Date,
Date,
Thread,
Author