Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Ah I agree it's better than my original. But it still feels unsatisfactory that I have to explicitly store the exit code to a variable. Is there no way to 'push' an exit code and 'pop' it again later? Commented Jan 11, 2015 at 2:34
  • @math4tots Try the update. Commented Jan 11, 2015 at 2:44
  • So with your update I would have to initialize last_error_code to zero and then return at the end so I would have non-zero exit code if any command threw an error? It is a cool trick, but for my two line hack script, I think I prefer @mikeserv 's answer. Commented Jan 11, 2015 at 6:35
  • @math4tots You can always do exit ${last_error_code:=0}. Commented Jan 11, 2015 at 11:17
  • @avip whatever for? It's already in single quotes, so the variable is only evaluated when the trap is called. Commented Jul 26, 2017 at 12:25