title: if-statement always evaluates to TRUE
body: <p>Is there any reason why this script always returns "running", regardless of whether my  process is started or stopped?</p>
  
  <pre><code>if ps ax | grep -v grep | grep "processName" &gt; /dev/null
  then
     echo $"running"
  else
     echo $"not running"
  fi
  </code></pre>
  
  <p>Thank you very much</p>
  
  <p><strong>UPDATE :</strong>
  I add a full example of my script, maybe there is something wrong elsewhere.</p>
  
  <pre><code>case "$1" in
    start)
      # Start daemons.
  
      echo -n $"Starting daemon: "
      ;;
  
    stop)
      # Stop daemons.
      echo -n $"Shutting down: "
      echo
      ;;
    status)
      pgrep -f "ProcessName" &gt; /dev/null
      if [ $? -eq 0 ]; then
          echo $"ProcessName is running"
      else
          echo $"ProcessName is not running"
      fi
      ;;
    restart)
      $0 stop
      $0 start
      ;;
  
    *)
      echo $"Usage: $0 {start|stop|status|restart}"
      exit 1
  esac
  </code></pre>
  
  <p><strong>UPDATE 2 :</strong></p>
  
  <pre><code>[user@dev init.d]# pgrep -f "MyProcess" &gt; /dev/null
  [user@dev init.d]# echo $?
  0
  [user@dev init.d]# service MyProcess stop
  Shutting down MyProcess: Terminated
  [user@dev init.d]# pgrep -f "MyProcess" &gt; /dev/null
  [user@dev init.d]# echo $?
  1
  </code></pre>
  
  <p>But <code>if [ $? -eq 0 ]; then</code> seems to be TRUE all the time</p>