[lug] How does bash "set -e" work?
Rob Nagler
nagler at bivio.biz
Fri Jan 4 10:10:05 MST 2013
Well, I looked at the code, and it's pretty complicated (and scary) stuff,
but it's pretty clear that there is passing in state to the child
(execute_cmd.c):
/* Make sure the subshell inherits any CMD_IGNORE_RETURN flag. */
if ((command->flags & CMD_IGNORE_RETURN) && tcom != command)
tcom->flags |= CMD_IGNORE_RETURN;
That's one place the out of band communication happening. "flags" is not
what gets set by "set -e", that's exit_immediately_on_error.
CMD_IGNORE_RETURN is set when you do an 'AND_AND' or 'OR_OR', etc.
It's pretty clear that the code is supposed to do what it is doing. You
can't control that. Indeed, there's not a single "clear" (&=
~CMD_IGNORE_RETURN) in the source. There's also no way to detect it in the
subshell either.
This lack of transparency is why we eschew shell programming in favor of
Perl. It's fairly ironic that this particular code is being used to build
our Perl modules bundle. :)
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20130104/7ef4ca8f/attachment.html>
More information about the LUG
mailing list