title: Bash exit status not working in script
body: <p>I've written a script that starts, stops and sends status of Apache, with messages dependent on the output of the commands.</p>
  
  <p>I have most of it correct, but my errors are not printing out correctly. In other words, even if I do not have Apache loaded, "stopping" it still shows a successful message. </p>
  
  <p>I need help getting my error messages to print when necessary.</p>
  
  <pre><code>#!/bin/bash
  
  echo -e "\e[1;30mApache Web Server Control Script\e[0m"
  echo
  echo "Enter the operation number to perform (1-4): "
  echo " 1 - Start the httpd server"
  echo " 2 - Restart the httpd server"
  echo " 3 - Stop the httpd server"
  echo " 4 - Check httpd server status"
  echo
  echo -n "===&gt; "
  read NUMBER
  
  EXITSTATUS=$?
  echo
  if [ $NUMBER -eq "1" ]; then
      systemctl start httpd
      if [ $EXITSTATUS -eq "0" ]; then
          echo -e "\e[1;32mThe return value of the command 'systemctl 
          start httpd' was 0.\e[0m"
          echo -e "\e[1;32mThe Apache web server was successfully 
          started.\e[0m"
      else
          echo -e "\e[1;31mThe return value of the command 'systemctl 
          start httpd' was 5.\e[0m"
      echo -e "\e[1;31mThe Apache web server was not successfully 
      started.\e[0m"
      fi  
  fi 
  
  if [ $NUMBER -eq "2" ]; then
      systemctl restart httpd
      if [ $EXITSTATUS -eq "0" ]; then
          echo -e "\e[1;32mThe return value of the command 'systemctl 
          restart httpd' was 0.\e[0m"
          echo -e "\e[1;32mThe Apache web server was successfully 
          restarted.\e[0m"
      else
          echo -e "\e[1;31mThe return value of the command 'systemctl 
          restart httpd' was 5.\e[0m"
          echo -e "\e[1;31mThe Apache web server was not successfully 
          restarted.\e[0m"
      fi  
  fi
  
  if [ $NUMBER -eq "3" ]; then
      systemctl stop httpd
      if [ $EXITSTATUS -eq "0" ]; then
          echo -e "\e[1;32mThe return value of the command 'systemctl 
          stop httpd' was 0.\e[0m"
          echo -e "\e[1;32mThe Apache web server was successfully 
          stopped\e[0m."
      else
          echo -e "\e[1;31mThe return value of the command 'systemctl 
          stop httpd' was 5.\e[0m"
          echo -e "\e[0;31mThe Apache web server was successfully 
          stopped.\e[0m"
      fi  
  fi
  
  if [ $NUMBER -eq "4" ]; then
      systemctl status httpd
      if [ $EXITSTATUS -eq "0" ]; then
          msg=$(systemctl status httpd)
      else
          echo -e "\e[1;31mThe Apache web server is not currently 
          running.\e[0m"
          echo $(msg)
      fi  
  fi
  
  if [[ $NUMBER != [1-4] ]]; then
      echo -e "\e[1;31mPlease select a valid choice: Exiting.\e[0m"
  fi
  exit 0
  </code></pre>