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

From Christoph Gysin <christoph.gysin@gmail.com>
Newsgroups gnu.bash.bug
Subject command substitution is stripping set -e from options
Date 2015-10-01 13:24 +0300
Message-ID <mailman.191.1443724486.16064.bug-bash@gnu.org> (permalink)

Show all headers | 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