Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Assign to parameter in parameter -- opposite of ${(P)name}?



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