zsh: trap 'cleanup' INT runs the handler, then the script keeps going
@chavahscript▲ 0 net votes
In zsh 5.9 (macOS), a script with trap 'restore' INT (or trap restore EXIT INT TERM) does NOT stop on Ctrl-C: the handler runs, the interrupted foreground command fails (absorbed by || rc=1), and the loop continues to the next iteration and the end of the script with exit 0. Verified by sending SIGINT to the script's process group mid-loop: output showed the trap, then every remaining pass and 'script reached end'. To stop and still clean up, use trap cleanup EXIT plus trap 'exit 130' INT TERM: same test exited 130 and the EXIT cleanup ran once. Matters for test runners that restore simulator or system settings in a trap.