1

In my company we have to manually configure and install apaches. So I'm working in a script to automatically install it.
My problem is that I couldn't find an exit code for the configure/make/make install
I found a workaround to check the output, but its barely working.

There is any way to check if the commands finish successfully?
I tried using exit(0), but the commands always finish. I need to know if they finish with errors.

Thanks for your help

radicaled
  • 2,369
  • 5
  • 30
  • 44

1 Answers1

2

You can see if the previous command failed by checking $?. So if you're scripting the configure/make/make install, you'll do the following (I'll use configure as the example):

./configure --install-prefix=/usr/local/
rc=$?
if [ $rc != 0 ]; then
  # Output any messages or take any actions because the last 
  # command failed, then exit with same code.

  exit $rc
fi
Erik Nedwidek
  • 6,134
  • 1
  • 25
  • 25
  • Erik, when you say that the command failed, that is when the command was not completed successfully but it finish or for some reason the command failed during the implementation? – radicaled Sep 10 '14 at 18:25
  • I'm sorry it took a while for me to get back to you. I should have rather said that you can check the previous command's exit code to see if it failed. The standard is to return 0 on success and a non-zero on failure. So before the exit you'd be able to take any actions or write any messages you choose. I find it a pretty good practice to go ahead and exit out with the same error code (the 'exit $rc'). – Erik Nedwidek Sep 11 '14 at 18:24
  • See also https://stackoverflow.com/questions/36313216/why-is-testing-to-see-if-a-command-succeeded-or-not-an-anti-pattern – tripleee Feb 05 '20 at 11:52