Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!csd4.milw.wisc.edu!uakari.primate.wisc.edu!indri!ames!vsi1!altos86!dtynan From: ehkinmonth@ucdavis.edu (Earl H. Kinmonth) Newsgroups: comp.unix Subject: set -e breaks some shell scripts Message-ID: <12382@altos86.Altos.COM> Date: 31 Jul 89 21:46:32 GMT Sender: dtynan@altos86.Altos.COM Reply-To: uunet!ucdavis.edu!ehkinmonth (Earl H. Kinmonth) Organization: University of California, Davis Lines: 31 Approved: dtynan@zorba.Tynan.COM Presumably what I'm going to describe is common knowledge for adepts, but for the benefit of a few other amateurs out there, I'm sharing my information (and frustrations). Situation: a shell script that runs under a half dozen varieties of the Bourne shell (and even the Korn shell under MSDOS) dies without explanation on a particular set of machines. In each case the death without explanation occurs in a construct of the form if test -r $F then echo found $F fi Using the set -x option shows that test is being executed AND that the shell is instantly exiting. After hours of frustration, switching back to other machines to verify that the code actually works, I see a "set -e" in the shell script. I comment it out, run the shell script, and it works! Analysis: for archaic versions of the Bourne shell, test is a separate program. If the -e option is on, a non-zero status is considered an execution failure, and the shell exits (unfortunately with no message). With more recent versions of /bin/sh and ksh, test is a built in function, and a non-zero status is recognized as a normal state of affairs and execution continues. Save your RTFM comments. I did RTFM, and if this problem is explained, I missed it.