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


Groups > gnu.bash.bug > #11572

Re: command substitution is stripping set -e from options

From Christoph Gysin <christoph.gysin@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: command substitution is stripping set -e from options
Date 2015-10-02 14:09 +0300
Message-ID <mailman.269.1443788211.16064.bug-bash@gnu.org> (permalink)
References <CADex794C1jOf0wrB298_O4ohAqZghYUdd9DJcuaOvV1dCP5AOQ@mail.gmail.com> <560D83DA.9020405@redhat.com>

Show all headers | View raw


> 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

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


Thread

Re: command substitution is stripping set -e from options Christoph Gysin <christoph.gysin@gmail.com> - 2015-10-02 14:09 +0300

csiph-web