title: Bash Script: egrep not returning results with single quote in variable
body: <p>I am writing a simple bash script that is doing the following:</p>
  
  <pre><code>cmd="egrep -i Hello /home/me/foo.txt"
  if [ -n $cmd ]
  then
      $cmd
      if [ $? -eq 0 ]
      then
          echo "YAY"
      else
          echo "BOO"
      fi
  fi
  </code></pre>
  
  <p>This returns "YAY". However, if I add single quotes around Hello, the scripts returns "BOO"</p>
  
  <pre><code>cmd="egrep -i 'Hello' /home/me/foo.txt"
  if [ -n $cmd ]
  then
      $cmd
      if [ $? -eq 0 ]
      then
          echo "YAY"
      else
          echo "BOO"
      fi
  fi
  </code></pre>
  
  <p>I have been wracking my brain trying different escapes of quotes and still the $? returns a 1 as long as there are quotes inside the $cmd variable. How do I format the $cmd using quotes to return a 0? Any help would be appreciated.</p>