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

Re: exec redirect prevents trap



On Apr 16, 12:59am, frederik@xxxxxxx wrote:
}
}     #!/bin/zsh
}     exec > >(tee -a /tmp/foo)
}     trap "echo hi" INT TERM EXIT
}     sleep 1d;
} 
} When I run it and hit ^C, it doesn't print anything. But when I remove
} the "exec" line and do the same, it prints "hi".

I suspect what you have here is a race condition.  When zsh exits,
it first sends a HUP signal to all its children, including the tee
process.  If tee dies before the exit trap runs, the "hi" will go
nowhere.

Try one of these:

    exec > >(trap '' HUP; tee -a /tmp/foo)

    exec > >(tee -a /tmp/foo &! )



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