title: How to trap a return code in a string and rerun
body: <p>So My question is I am trying to figure how to read the output from the commands i posted. </p>
  
  <p>So the output pastes a block of text showing the result of the import and in the text it also either says exit code = 0 if it has worked or exit code = 255 if it has not. So i want the string to take that exit code from the text and then depending on the error code it should either re-run the command and try again three times or quit the program if it has worked. </p>
  
  <pre><code>#!/bin/bash
  #
  i="0"
  while [ $i -ne 3 ]
  do
  
      string1=$(sudo -u nginx php /var/www/html/shell/global/full_import.php --import finance_backup)
      string2=$(sudo -u nginx php /var/www/html/shell/global/full_import.php --import finance_deactivate_quotes)
      string3=$(sudo -u nginx php /var/www/html/shell/global/full_import.php --import finance)
  
      if [ "$string1" == "code = 255" ] || [ "$string2" == "code = 255" ] || [ "$string3" == "code = 255" ]
  then
  
      sudo -u nginx php /var/www/html/shell/global/full_import.php --import finance_backup
      sudo -u nginx php /var/www/html/shell/global/full_import.php --import finance_deactivate_quotes
      sudo -u nginx php /var/www/html/shell/full_import.php --import finance
      ((i++))
      sleep 3s
      echo it works
  fi
  string3="exit code = 0"
  echo It works
  done
  </code></pre>