home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 46.5 Stop Syntax Errors in String Tests Chapter 46
Shell Script Debugging and Gotchas
Next: 46.7 Quoting and Command-Line Parameters
 

46.6 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 ( 1.8 ) , 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 ( 38.4 ) without the -e flag.

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


Previous: 46.5 Stop Syntax Errors in String Tests UNIX Power Tools Next: 46.7 Quoting and Command-Line Parameters
46.5 Stop Syntax Errors in String Tests Book Index 46.7 Quoting and Command-Line Parameters

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru