I'm trying to create a function which I can define in .zshenv which will let me log when a command fails. Here's what I end up doing most of the time: LOG=$HOME/.foo.log if ((! foo )) then echo "$0: command 'foo' failed" | tee -a "$LOG" exit 1 fi if ((! bar )) then echo "$0: command 'bar' failed" | tee -a "$LOG" exit 1 fi Here is what I'd like to be able to do instead foo || failed bar || failed if 'failed' get called, I want the shell script (whatever called `foo` and `bar`) to exit 1, and I want to log the name of the command that failed (and, ideally, the name of the script that `foo` or `bar` was in when it failed) (These are simple examples, of course, but it gets more complicated when `foo` or `bar` are longer commands, or part of a loop, etc.) Is there a way to do this? If so, I'd appreciate any hints suggestions, or examples you could give. Thanks TjL