bin/111343: sh(1) and bash(1) with -e sometimes fail to testerrors in functions

Alexander Melkov melkov at comptek.ru
Mon Sep 14 10:40:06 UTC 2009


The following reply was made to PR bin/111343; it has been noted by GNATS.

From: "Alexander Melkov" <melkov at comptek.ru>
To: "Jilles Tjoelker" <jilles at stack.nl>,
	<bug-followup at FreeBSD.org>
Cc:  
Subject: Re: bin/111343: sh(1) and bash(1) with -e sometimes fail to testerrors in functions
Date: Mon, 14 Sep 2009 14:18:06 +0400

 > Replacing the function call with the function definition, the behaviour
 > seems reasonable.
 Ok, thanks. The problem is much worse then.
 ==> test1.sh <==
 set -e
 
 { false; echo ok; } || echo failed
 if ! { false; echo ok; } ; then
   echo failed
 fi
 if ! ( false; echo ok; ) ; then
   echo failed
 fi
 - outputs
 ok
 ok
 ok
 
 > The command is tested, so -e should not trigger.
 Why testing the command should change the operation *within* that command? 
 That's well beyond traditional programming, thus obviously a bug.
 
 > In general, set -e is not a good idea for more complicated scripts
 > because its rules can be confusing and inconsistent across shells. You
 > can achieve a similar effect by putting '|| exit' after commands.
 Ok, very nice. I'll just take my 10000 lines of scripts and add 10000 times 
 '|| exit'.
 Actually -e is well defined and operates reliably except the case mentioned 
 in this PR.
 


More information about the freebsd-bugs mailing list