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

Re: Overriding "builtin"



From: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Aug 2022 07:12:56 +0000
> ?oàn Tr?n Công Danh wrote on Fri, 12 Aug 2022 02:24 +00:00:
> > On 2022-08-11 20:18:49-0500, Zach Riggle <zachriggle@xxxxxxxxx> wrote:
> >> I recently learned that 'builtin' can be overridden with a function.  Neat
> >> for some silly tricks!
> >> 
> >> However, is there a way to save / restore 'builtin' such that it can be
> >> restored?
> >> 
> >> All that I can think of is 'unfunction builtin', but 'unfunction' itself
> >> can be overridden with a function.
> >
> 
> «unset 'functions[unfunction]'», provided (zsh/parameter is available
> and) someone hasn't created an unset() function as well.
> 
> > You can run original builtin with "builtin".
> >
> > e.g.:
> >
> > echo() { printf '++%s\n' "$@"; }
> > echo this will run function
> > builtin echo this will run builtin
> 
> No, he can't, because in his case that'd be a bottomless recursive call
> (= an infinite loop).

Hm... this works here as I'd expect, but since you said "in his case"
there may be something that turns that into a non-terminating recursion
just for Zach's case. But what? (Always eager to learn something :-/ )

Tom




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