[lug] How does bash "set -e" work?
Rob Nagler
nagler at bivio.biz
Sat Dec 29 09:50:31 MST 2012
I've always wondered about "set -e" in subshells. Here's a simple script:
sh -x <<'EOF'
(set -e; false; echo not1) || echo ok1
(set -e; false; echo not2); echo ok2
(false && echo not3) || echo ok3
(false && echo not4); echo ok4
set -e
echo ok5
false
echo not6
EOF
What I would expect is:
ok1
ok2
ok3
ok4
ok5
However, that's not the case. I get:
not1
ok2
ok3
ok4
ok5
It seems that the "set -e" is affecting the parent shell.
Am I missing something?
Rob
More information about the LUG
mailing list