Subject: Re: exec redirect prevents trap
From: Bart Schaefer <[email-masked]>
To: [email-masked], [email-masked]
Date: Sat, 16 Apr 2016 09:34:33 -0700
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Apr 16, 12:59am, [email-masked] 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 &! )