-- Drupal and Web Development

Notice: this post was last updated 3 years 32 weeks ago so it might be outdated. Please be cautious before implementing any of suggestions herein.

Exit parent process with the code of the child process on Mac OS X

Sometimes you want the parent process to exit with the child process's code. In the example below, whatever is in parentheses is child code. For example, calling exit 1 directly exists the process, but calling (exit 1) does not exit the process.

(exit 1)
#parent still running
(exit 0)
#parent still running
(exit 1)
#parent still running
[ $? = 0 ] || exit $?
# exit parent with exit code of child process if non-zero.

$? corresponds to the last exit code of the child process. What we are doing is checking if it is equal to zero, and if it is not, continue by exiting with that exit code.

Mac OS X, CentOS and other systems seem to behave differently with regards to exit codes when using Jenkins: on CentOS, a Jenkins Job will fail if any of the commands fail. On Mac OS X, if you don't add the line [ $? = 0 ] || exit $? to the shell script, the job never seems to fail.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.