[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)'
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
- command substitution is stripping set -e from options,
Christoph Gysin <=
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/08
- Re: command substitution is stripping set -e from options, Eric Blake, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Greg Wooledge, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08
- Re: command substitution is stripping set -e from options, Chet Ramey, 2015/10/08
- Re: command substitution is stripping set -e from options, Christoph Gysin, 2015/10/08