title: How to exit if statement in bash without exiting program?
body: <p>Rewriting this question to avoid more downvotes, since it's too late for me to delete it:</p>
  
  <p>I'm writing a script that asks a user for confirmation and before <code>sourcing</code> some other scripts. To simplify the code, imagine that there are two scripts which might be <code>sourced</code>, but I want the user to either <code>source</code> none or exactly one of the scripts - not both. I was trying to use a statement of the form <code>if true source-script else exit</code> which wasn't working because I'd exit the <code>if</code> statement, but also the script as a whole, and wouldn't have a chance to do necessary cleanup. Originally, my script looked something like this:</p>
  
  <pre><code>echo "This script might do something terrible to your computer."
  read -p "Do you wish to continue? (y/[n]) " -n 1;
  echo
  if ! [[ $REPLY =~ ^[Yy]$ ]]
  then
      source "terrible_script.sh"
      # want some way to ensure that we don't prompt the user about the next script
      # don't want to just exit if the response is 'n' because we have to do cleanup
  fi
  
  echo "This script might do something really good to your computer."
  read -p "Do you wish to continue? (y/[n]) " -n 1;
  echo
  if ! [[ $REPLY =~ ^[Yy]$ ]]
  then
      source "good_script.sh"
  fi
  
  # do cleanup here
  # regardless of whether or not any scripts were sourced
  </code></pre>
  
  <p>@charles-duffy provided the answer - simply wrap the prompts in a function. Something like:</p>
  
  <pre><code>function badscript() {
      echo "This script might do something terrible to your computer."
      read -p "Do you wish to continue? (y/[n]) " -n 1;
      echo
      if ! [[ $REPLY =~ ^[Yy]$ ]]
      then
          source "terrible_script.sh"
          return 0
      fi
  }
  
  function goodscript() {
      echo "This script might do something really good to your computer."
      read -p "Do you wish to continue? (y/[n]) " -n 1;
      echo
      if ! [[ $REPLY =~ ^[Yy]$ ]]
      then
          source "good_script.sh"
      fi
  }
  
  if ! badscript
  then
      goodscript
  fi
  
  # cleanup code here
  </code></pre>