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

Re: Interpret Parameter Value at Time of Function Definition



On Tue, Sep 5, 2017 at 9:17 AM, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Vin Shelton wrote on Tue, 05 Sep 2017 09:47 -0400:
>> $ aaa=bbb
>> $ function t {
>>     print aaa = \"$aaa\"
>>   }
>>
>> I would like to interpret $aaa at read time [...]
>
> Declare aaa local inside the function:

That won't help if the value assigned to $aaa is itself going to
contain expansions.

As Martijn points out, the only way to get this to work is with some
kind of "read-time" evaluation.  Exactly what approach is best depends
on what you want to accomplish.  Does $aaa expand to executable
statements that you want to turn into part of the function code, or
does it just result in a value that you want to access later?

No matter which way you go, the key is that you'll need to quote the
function body differently than you quote the value you want assigned
to $aaa.



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