Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail From: Greg Wooledge Newsgroups: gnu.bash.bug Subject: Re: command substitution is stripping set -e from options Date: Fri, 2 Oct 2015 08:29:26 -0400 Lines: 29 Approved: bug-bash@gnu.org Message-ID: References: <560D83DA.9020405@redhat.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1443791879 14199 208.118.235.17 (2 Oct 2015 13:17:59 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Christoph Gysin Envelope-to: bug-bash@gnu.org Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 139.137.100.1 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11574 On Fri, Oct 02, 2015 at 02:09:21PM +0300, Christoph Gysin wrote: > Since set -e does not work, it means I have to postfix every command > with "|| exit $?": > > f() { > some command || exit $? > more commands --with-args || exit $? > } > > output=$(f) Since it's a function, I would recommend return instead of exit. Also, you don't need the $? there. exit (or return) with no arguments will retain the exit status of the previous command. > My understanding was the the whole point of set -e was to have that > behaviour by default for every command (with the documented > exceptions). That was the INTENT, perhaps, of the original designers way back in the ancient Bourne shell days, but that is never how it WORKED in real life. The crazy shell command syntax just made it too quirky and unreliable. So they made exceptions, and then exceptions to the exceptions, and so on until we have the current unusable mess. Putting "|| return" or "|| exit" after all critical commands in your script is precisely what you should do. (Some people write a die() function and then use "|| die 'my message'" instead.)