[lug] How does bash "set -e" work?
    Rob Nagler 
    nagler at bivio.biz
       
    Sun Dec 30 12:00:48 MST 2012
    
    
  
> you were all in the same bind. :-)
No, I was trying to wrap my head around ExtUtils::MakeMaker and
Module::Build so to build RPMs for CentOS 5.6 and 6.2.  Also not very
intuitive. :-(
What's confusing me about set -e is that the subshell's behavior is
being affected by something the supershell is doing.
sh -c 'set -e; false; echo subshell' || echo ok
This works as I would expect the subshell to work.
Not sure how the subshell is detecting this case:
(set -e; { set; env; } | sort > y)
(set -e; { set; env; } | sort > x) || echo ok
diff x y
This is empty.  The "||" isn't modifying stdout so how would it "know"
except by some internal state passed in the fork.  However, it seems
like this state (in a boolean expression) should be detectable in the
subshell.
Anyway, I'm just putting "|| exit 1" in the right places, and that
does the trick.
Rob
    
    
More information about the LUG
mailing list