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

Re: Refering to overlaid variable from within a function



On 2010-09-10 at 07:35 -0700, Bart Schaefer wrote:
> On Sep 10,  2:13am, Phil Pennock wrote:
> }
> } Is there a way to refer to variables as they exist in the context of the
> } caller of a function, so that you can use a name but not have to worry
> } about the caller's names?
> 
> Yes, but it's sneaky.
> 
>     bar () {
>         local a="this is bar's $1"
>         print $a
>         trap "$1+=\" and \"${(q-)a}" EXIT
>     }
>     foo () {
>         local a="this is foo's a"
>         print $a
>         bar a
>         print $a
>     }
> 
> Now run "foo".

% foo
this is foo's a
this is bar's a
bar:3: error in flags

Tried with 4.3.10 and 4.3.9.

Dropping the '-' from the parameter expansion flags does the trick.
I'll think on it some more, to deal with the unique-ified arrays needed
for the sets.  I might just end up switching back to working on the
positional parameters.

Thanks,
-Phil



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