title: Bash script for macOS Loop if then else
body: <p>Trying to do a loop with this script below.  It works if I break it by deleting Google Chrome from Applications.  If I put Chrome back into place it continuously kills the dock and says No matching processes belonging to you were found.  Do I have to add something to killall Dock to exit the script or is Done in the wrong spot?  Tried multiple things without any luck.  Eventually want it to try every 15 minutes until all apps are in Applications and kill the dock so the shortcuts show instead of Question marks.  This will happen once all apps get installed and Dock gets restarted.</p>
  <pre><code>i=0
  while [ $i -lt 4 ]
  do
  if [[ -d &quot;/Applications/Company Portal.app&quot; &amp;&amp; -d &quot;/Applications/Google Chrome.app&quot; ]];
          then
                  killall Dock         
          else
  i=$((i + 1)) | echo &quot;Will tray again....&quot;
  sleep 10
  fi
  done
  </code></pre>
  <p><strong>Update</strong> Here is what I eventually came up with, yea messy!  But works!  Will have to look at it more after see the responses here though.</p>
  <pre><code>echo $(date)
  
  # Check to see if script has already run on computer before, if so, then exit.
  file=/Users/Shared/.If_Installed_Restart_Dock_Has_Run.txt
  if [ -e &quot;$file&quot; ]; then
      echo &quot;The If_Installed_Restart_Dock.sh script has run before and exiting...&quot; &amp;&amp; exit 0
  else
  touch /Users/Shared/.If_Installed_Restart_Dock_Has_Run.txt
  fi
  
  i=0
  while [ $i -lt 6 ]
  do
  
  if [[ -d &quot;/Applications/Google Chrome.app&quot; &amp;&amp; -d &quot;/Applications/Microsoft Edge.app&quot; ]];
          then
                  killall Dock &amp;&amp; exit 0
          else
                  echo &quot;Applications still need installed in order to restart Dock, will check again in 10 minutes for up to an hour, intune will try again in 8hrs...&quot;
  fi
  
  i=$((i + 1))
  sleep 600
  done
  </code></pre>