title: Replacing too many if statements in bash
body: <p>I have written a bash script which works as follows</p>
  
  <pre><code>1) Check for status of service1. If it is not started then check for status of service2. If service2 is not started then display error.
  2) If service1 is started then check for log file of service1 and grep for `starting`. If it matches then success
  3) If service2 is started then check for log file of service1 and grep for `starting`. If it matches then success
  </code></pre>
  
  <p>My bash script looks as below but it has too many if statements. I am trying to figure out to reduce these many if statements</p>
  
  <pre><code>#!/bin/bash
  service service1 status | grep "good" &gt; /dev/null
  if [ $? -ne 0 ];then
      service service2 status | grep "good" &gt; /dev/null
      if [$? -ne 0];then
          var1="service1 is down"
          echo "$var1"
      else
          cat /dir/log2 | grep "abc" &gt; /dev/null 2&gt;&amp;1
          if [ $? -ne 0 ];then
              var2="exception"
              echo "$var2"
          fi
      fi
  else
      cat /dir/log1 | grep "abc" &gt; /dev/null 2&gt;&amp;1
      if [ $? -ne 0 ];then
          var3="exception"
          echo "$var3"
      fi
  fi
  </code></pre>