On Mon, Oct 15, 2012 at 11:23 AM, Nikolai Kondrashov <nikolai.kondras...@redhat.com> wrote: > Hi everyone, > > I've noticed that errexit is disabled inside command substitution. > Is this intentional? > > It makes it hard to save and restore errexit state. I.e. you can't simply > say > opts=`set +o`, because errexit will always be stored as off. What's > interesting, $SHELLOPTS shows it still on inside the command substitution. > > Sincerely, > Nick >
Errexit only causes the shell to exit when the exit status of the entire simple command is false. Therefore, it depends on the context. For example: set -e foo=$(false) This will exit. Assignments preserve the exit status of the command within a command substitution. However, set -e true "$(false)" This will not exit. The exit status is not preserved in that case, and the exit status of the entire command is true. My advice is to stop using errexit at all. Your life will be much, much easier that way. As an aside, check out http://mywiki.wooledge.org/BashFAQ/105 for other issues with errexit.