bug-bash
[Top][All Lists]
Advanced

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

Subshell inheritance of -e


From: Freddy Vulto
Subject: Subshell inheritance of -e
Date: Sat, 20 Dec 2008 15:13:25 -0800 (PST)
User-agent: G2/1.0

 I'm having a hard time understanding how bash propagates `-e' to a
subshell.  Considering the example script below:
- shouldn't C, D and E give no output?  I know `-e' isn't in effect if
the test is part of a `&&', `||' or `!', but shouldn't `-e' be *in*
effect because the `&&', `||' or `!' are defined outside of the
subshell?
- shouldn't the lefthand and righthand subshells of the `&&' behave
the same in FGH, IJK and PQRS?  Especially since LMNO works like
expected?

I'm running GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)

---8<---------------------------------------------------
#!/bin/bash -e
# Investigating `-e' subshell behaviour
echo $(false; echo A)
# output: A; no exit within `$()'
(false; echo B)
# output: none; exits within `()'
(false; echo C) || true
# output: C; no exit within `()'
(false; echo D) && true
# output: D; no exit within `()'
!(false; echo E)
# output: E; no exit within `()'
(false; echo F) && (echo G; false; echo H)
# output: FG; exits within right `()' only
!(false; echo I) || (echo J; false; echo K)
# output: IJ; exits within right `()' only
echo $(set -e; echo L; false; echo M) && echo $(set -e; echo N; false;
echo O)
# output: LN; exits within `$()' if `-e' set explicitly
(set -e; echo P; false; echo Q) && (set -e; echo R; false; echo S)
# output: PQR; exits within right `()' only
---8<---------------------------------------------------

Regards, Freddy Vulto


reply via email to

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