title: Bash script not exiting once a process is running
body: <p>How should I modify my bash script logic so it exits the while loop and exits the script itself once a process named custom_app is running on my local Ubuntu 18.04? I've tried using break and exit inside an if statement with no luck.</p>
  
  <p>Once custom app is running from say...1st attempt then I quit the app, run_custom_app.sh lingers in the background and resumes retrying 2nd, 3rd, 4th, 5th time. It should be doing nothing at this point since app already ran successfully and user intentionally quit.</p>
  
  <p>Below is run_custom_app.sh used to run my custom app triggered from a website button click.</p>
  
  <p>Script logic</p>
  
  <ol>
  <li>Check if custom_app process is running already. If so, don't run the commands in the while code block. Do nothing. Exit run_custom_app.sh.</li>
  <li><p>While custom_app process is NOT running, retry up to 5 times.</p></li>
  <li><p>Once custom_app process is running, stop while loop and exit run_custom_app.sh as well.</p></li>
  <li>In cases where 5 run retries have been attempted but custom_app process is still not running, display a message to the user.</li>
  </ol>
  
  <pre><code>#!/bin/sh
  
  RETRYCOUNT=0
  PROCESS_RUNNING=`ps cax | grep custom_app`
  
  # Try to connect until process is running. Retry up to 5 times. Wait 10 secs between each retry.
  
  while [ ! "$PROCESS_RUNNING" ] &amp;&amp; [ "$RETRYCOUNT" -le 5 ]; do
    RETRYCOUNT="`expr $RETRYCOUNT + 1`"
  
    commands
  
    sleep 10
  
    PROCESS_RUNNING=`ps cax | grep custom_app`
  
    if [ "$PROCESS_RUNNING" ]; then
      break
    fi
  done
  
  
  # Display an error message if not connected after 5 connection attempts
  if [ ! "$PROCESS_RUNNING" ]; then
    echo "Failed to connect, please try again in about 2 minutes"   # I need to modify this later so it opens a Terminal window displaying the echo statement, not yet sure how.
  fi
  </code></pre>