[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

command substitution is stripping set -e from options

From: Christoph Gysin
Subject: command substitution is stripping set -e from options
Date: Thu, 1 Oct 2015 13:24:18 +0300

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

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.

echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]