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

Re: Load autoloadable function, but only in enclosing function scope



On 3/24/22, Zach Riggle <zachriggle@xxxxxxxxx> wrote:
> Is there a way to
>
> myfunc() {
>     autoload foo && foo
> }
>
> Such that foo and any other functions it declares are local-scope only?

Functions are never scoped at all, so no. You can manually unfunction
it afterwards (if there was already a function with a conflicting
name, autoload returned success and you ran the wrong function
anyway). If you don't need any other side effects from myfunc, you can
run the whole thing in a subshell of course.

-- 
Mikael Magnusson




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