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


Groups > gnu.bash.bug > #11568

command substitution is stripping set -e from options

Path csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail
From Christoph Gysin <christoph.gysin@gmail.com>
Newsgroups gnu.bash.bug
Subject command substitution is stripping set -e from options
Date Thu, 1 Oct 2015 13:24:18 +0300
Lines 29
Approved bug-bash@gnu.org
Message-ID <mailman.191.1443724486.16064.bug-bash@gnu.org> (permalink)
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace usenet.stanford.edu 1443724486 11246 208.118.235.17 (1 Oct 2015 18:34:46 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=Tgg7rZjCk6lPUCpX3bXmdMpw995fdUgNxgOtuc8aGz0=; b=cuJON5A5lbNOXOtEV488WPXuHNd0RfbM4TZAIxoG9hdYHCtJcwT+svF1RiUhRvOlr1 iqXJUz9uKowwJZK1r40FF0bw7SN648Nhjh91570tAOGfrQvbak9CVWlUzDESbeBLSJpF 2x2fcNZSo6gHta2pxIjaZsfMChWqaPTvQCJl0pbxW96cXKS2ugsED7Lu70VNOgfzPBfr 4f+HSINm6C62Xh1aT4SvPyGRtFdFEYG0Lcgq8Tt4SRvTmQVgSkwIWs+p6L+DfrO5IEwf WW2TU+MzPf55tyegZydb6Tq+hCyYop0tB4YEMCTRWOIcnJ6jZm4c2Aer3MN5NPgi8i7K zt+g==
X-Received by 10.25.19.73 with SMTP id j70mr1716823lfi.29.1443695097848; Thu, 01 Oct 2015 03:24:57 -0700 (PDT)
X-detected-operating-system by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value).
X-Received-From 2a00:1450:4010:c04::236
X-Mailman-Approved-At Thu, 01 Oct 2015 13:50:37 -0400
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:11568

Show key headers only | View raw


It seems that set -e is stripped from the options ($-) when executing
commands with command substitution:

$ bash -euc 'echo $-; f(){ false; echo $->&2; }; x=$(f)'
ehuBc
huBc

I would expect the shell to exit as soon as it executes 'false'.

Is this intended? Is it documented somewhere?

I'm trying to catch errors in shellscripts by starting them with:

  set -euo pipefail

It seems now that this is not enough, I would have to start every
command substitution with set -e:

  var=$(set -e; command1; command2)

It *seems* to work with only a single command, because the return
value of the assignment is the last command executed inside the
command substitution. But if there are multiple commands, or a
function call, errors are not caught.

Chris
-- 
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org@fr33z3

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


Thread

command substitution is stripping set -e from options Christoph Gysin <christoph.gysin@gmail.com> - 2015-10-01 13:24 +0300

csiph-web