Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11574

Re: command substitution is stripping set -e from options

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
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 <mailman.272.1443791879.16064.bug-bash@gnu.org> (permalink)
References <CADex794C1jOf0wrB298_O4ohAqZghYUdd9DJcuaOvV1dCP5AOQ@mail.gmail.com> <560D83DA.9020405@redhat.com> <CADex795r=oqZ7iv4TxrjUn9coDUnu=PgPngkfRWA1f7EZyohfA@mail.gmail.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 <christoph.gysin@gmail.com>
Envelope-to bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <CADex795r=oqZ7iv4TxrjUn9coDUnu=PgPngkfRWA1f7EZyohfA@mail.gmail.com>
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 <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:11574

Show key headers only | View raw


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.)

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: command substitution is stripping set -e from options Greg Wooledge <wooledg@eeg.ccf.org> - 2015-10-02 08:29 -0400

csiph-web