Watch Out for Bourne Shell -e Bug

The Bourne shell -e option should stop execution when a command returns a non-zero status. Does your -e option seem to cause some if commands to abort scripts? If so, you have a copy of the Buggy Bourne Shell, as distributed with 4.2BSD, 4.3BSD, and probably several other systems. It can be identified by running:

$ set -e $ if false; then echo yipe; 
else echo ok; fi

and noting that the shell exits instead of printing ok, and by:

|| 
$ set -e $ false || echo ok

which also exits and should not, and by:

$ set -e $ while false; do :; done

To fix it, first get the source, and then change it in the obvious three places in xec.c. You will have to learn Bournegol [the ALGOL-like dialect of C that Steve Bourne used to write the original Bourne shell-JP ]. Another alternative is to replace /bin/sh with one of the free sh look-alikes (), provided you can find one that is enough alike.

As a workaround, you can set +e around all the tests that might fail. Unfortunately, some versions of the Buggy Bourne Shell do not even support set +e; here the only workaround is to run a subshell () without the -e flag.

- CT in comp.unix.questions on Usenet, 20 February 1990