diff --git a/core/main_loop.py b/core/main_loop.py index 1d616ffa8e..cfae324a0a 100644 --- a/core/main_loop.py +++ b/core/main_loop.py @@ -87,14 +87,12 @@ def Interactive(opts, ex, c_parser, display, errfmt): ui.PrintAst([node], opts) break - is_control_flow, is_fatal = ex.ExecuteAndCatch(node) + is_return, _ = ex.ExecuteAndCatch(node) status = ex.LastStatus() - if is_control_flow: # e.g. 'exit' in the middle of a script + if is_return: done = True break - if is_fatal: # e.g. divide by zero - break break # QUIT LOOP after one iteration. @@ -157,10 +155,10 @@ def Batch(ex, c_parser, arena, nodes_out=None): #log('parsed %s', node) - is_control_flow, is_fatal = ex.ExecuteAndCatch(node) + is_return, is_fatal = ex.ExecuteAndCatch(node) status = ex.LastStatus() - # e.g. divide by zero or 'exit' in the middle of a script - if is_control_flow or is_fatal: + # e.g. 'return' in middle of script, or divide by zero + if is_return or is_fatal: break return status diff --git a/osh/cmd_exec.py b/osh/cmd_exec.py index f2a0d5b92e..b42700d1e5 100755 --- a/osh/cmd_exec.py +++ b/osh/cmd_exec.py @@ -1193,14 +1193,14 @@ def ExecuteAndCatch(self, node, fork_external=True): - _Eval() for eval builtin - _RunFunc() for function call """ - is_control_flow = False + is_return = False is_fatal = False try: status = self._Execute(node, fork_external=fork_external) except _ControlFlow as e: # Return at top level is OK, unlike in bash. if e.IsReturn(): - is_control_flow = True + is_return = True status = e.StatusCode() else: # Invalid control flow @@ -1234,7 +1234,7 @@ def ExecuteAndCatch(self, node, fork_external=True): self.dumper.MaybeDump(status) self.mem.SetLastStatus(status) - return is_control_flow, is_fatal + return is_return, is_fatal def MaybeRunExitTrap(self): """If an EXIT trap exists, run it. @@ -1247,8 +1247,8 @@ def MaybeRunExitTrap(self): """ handler = self.traps.get('EXIT') if handler: - is_control_flow, is_fatal = self.ExecuteAndCatch(handler.node) - return is_control_flow # explicit exit/return in the trap handler! + is_return, is_fatal = self.ExecuteAndCatch(handler.node) + return is_return # explicit 'return' in the trap handler! else: return False # nothing run, don't use its status