bug-bash
[Top][All Lists]
Advanced

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

Re: command substitution is stripping set -e from options


From: Christoph Gysin
Subject: Re: command substitution is stripping set -e from options
Date: Fri, 2 Oct 2015 14:09:21 +0300

> Whether e disappears from $- may be unintended, but what IS documented
> is that there are contexts in which set -e has no effect, and when in
> one of those contexts, you cannot re-enable set -e.  One such context is
> on the left side of && or ||.  Even more non-intuitively, if you have a
> function that tries to use set -e, the effect of set -e depends on the
> context of where the function is called (that is, 'f' may behave
> differently than 'f || true').

Yes, I'm aware of all those, and I think they make sense. They are
also documented.

> What's wrong with:
>   var=$(command1 && command2) || exit

Because the code is:

f() {
  some command
  more commands --with-args
}

output=$(f)

Since set -e does not work, it means I have to postfix every command
with "|| exit $?":

f() {
  some command || exit $?
  more commands --with-args || exit $?
}

output=$(f)

My understanding was the the whole point of set -e was to have that
behaviour by default for every command (with the documented
exceptions).

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



reply via email to

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