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


Groups > gnu.bash.bug > #11594

Re: command substitution is stripping set -e from options

Path csiph.com!goblin3!goblin1!goblin.stu.neva.ru!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 Thu, 8 Oct 2015 14:49:39 -0400
Lines 27
Approved bug-bash@gnu.org
Message-ID <mailman.50.1444330330.4386.bug-bash@gnu.org> (permalink)
References <CADex794C1jOf0wrB298_O4ohAqZghYUdd9DJcuaOvV1dCP5AOQ@mail.gmail.com> <560D83DA.9020405@redhat.com> <CADex795r=oqZ7iv4TxrjUn9coDUnu=PgPngkfRWA1f7EZyohfA@mail.gmail.com> <20151002122925.GK25574@eeg.ccf.org> <CADex797-gWHRzpy=gsdORZtU=Os5Qe6f=LwJ7xJ-N-6oHZdd3w@mail.gmail.com> <20151002132221.GL25574@eeg.ccf.org> <56103208.30406@case.edu> <CADex794ttQa_b9NBGKJMsXj36yoRL3JQ16aja=S8=hAxGgzCQA@mail.gmail.com> <56168B10.1000905@case.edu> <CADex796=T3x11Y5Tz7udh7UzpYDaOY+0-EatZrAu2hGNRZ=gqg@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 1444330331 25911 208.118.235.17 (8 Oct 2015 18:52:11 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 <CADex796=T3x11Y5Tz7udh7UzpYDaOY+0-EatZrAu2hGNRZ=gqg@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:11594

Show key headers only | View raw


On Thu, Oct 08, 2015 at 09:36:59PM +0300, Christoph Gysin wrote:
> But this issue brings a new corner case:
> 
>   func() {
>     cmd1
>     cmd2
>   }
> 
>   var=$(func)
> 
> This won't work, because set -e is stripped inside the substitution,
> so the whole function runs without error checking.

I know you don't want to hear this, but you really need to stop thinking
of set -e as "error checking".  It is an obsolescent historical anomaly
that bash is required to support because POSIX specifies it.  It isn't
useful for any purpose, and people who insist on using it are simply
causing extra pain for themselves.

Bash does not have automatic error checking.  Instead, it uses the C
model: you need to check for erroneous results yourself, after every
command whose results you actually care about.

If you dislike this, then switch your project to a programming language
that *has* automatic error checking.  Bash is just a shell, and there
are many other languages that may better suit your project.

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-08 14:49 -0400

csiph-web