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

Re: is variable with variable name possible?



On 4 April 2011 18:28, Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote:
> 2011-04-04 16:25:01 +0200, Mikael Magnusson:
>> On 4 April 2011 16:06, Stephane Chazelas <stephane_chazelas@xxxxxxxx> wrote:
>> > 2011-04-04 15:48:32 +0200, Jérémie Roquet:
>> > [...]
>> >> 2011/4/4 zzapper <david@xxxxxxxxxx>:
>> >> > somevar=$(pwd)
>> >> >
>> >> > but I want somevar to be a variable name
>> >>
>> >> $ eval "$somevar=$(pwd)"
>> > [...]
>> >
>> > No!
>> >
>> > eval "$somevar=\$(pwd)"
>> > or
>> > eval "$somevar=\$PWD"
>> >
>> >
>> > Or think of what would happen if $PWD was "/tmp/x;rm -rf /home"
>>
>> How do you feel about this?
>> : ${(P)somevar::=$PWD}
> [...]
>
> Try after
>
> sudo ln -s . '/*'
> cd '/*/*/*/*/*'
> setopt globsubst
>
> ;-)
>
> (if you're lucky, it won't crash your machine).

Pretty sure globsubst breaks your idea too, but fine,
: ${(P)~~somevar::=$PWD}
In fact, globsubst pretty much breaks every hook function i have :P.

-- 
Mikael Magnusson



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