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

Re: function definition with & operator

On Fri, Sep 1, 2017 at 2:23 PM, Eric Cook <llua@xxxxxxx> wrote:
> On 09/01/2017 04:46 PM, Bart Schaefer wrote:
>> On Fri, Sep 1, 2017 at 11:09 AM, Eric Cook <llua@xxxxxxx> wrote:
>>> The other week when messing around i noticed that you can define an function
>>> in (what i thought would be) the background and it will remain in defined.
>> Background jobs are always run in a subshell,
> Exactly what i thought, but if that were the case, foo wouldn't be defined after
> the first example since & was the terminator used instead of ;.

Oh, I see.  I read "in defined" as a typo or auto-correct-o for
"undefined" and thought you were complaining about the "{ ... } &"

Yes, this is odd, and it appears to have always been this way.
However, it's a bit more than a minor bug, because it also affects
anonymous functions; compare:

    zsh -fc '{ sleep 10 } & print $SECONDS'
    zsh -fc '() { sleep 10 } & print $SECONDS'

What's going on here is that a function definition is not actually a
command, it's a syntax construct that is special-cased in exec.c.
However, I'm not sure how to resolve it.

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