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

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



Benjamin R. Haskell wrote:
> On Sat, 10 Jul 2010, Frank Terbeck wrote:
>> Benjamin R. Haskell wrote:
>> > It's the end of the week, and I'm tired, so I'm sure I'm completely 
>> > overlooking something obvious, but how do you *assign* to a 
>> > parameter whose name is in a parameter?
>> [...]
>> > Do I need to resort to 'eval'?
>> 
>> % typeset foobar=baz
>> % print ${foobar}
>> baz
>> 
>
> I was tired... but not thaaat tired... :-)
>
> Using different variable names, I was looking for:
>
> name=xyzzy
> value=asdf
>
> # <-- something that doesn't involve the string xyzzy
>
> echo $xyzzy # echoes 'asdf'

Yes. But the "foobar=baz" part is just a parameter to a builtin
command. Hence you can do this:

% name=foobar
% typeset ${name}=baz
% print $foobar
baz

I thought that was what you were after. If not, I must have
misunderstood the problem entirely. :)

Regards, Frank



Messages sorted by: Reverse Date, Date, Thread, Author