title: How to grep a continuous stream from the CLI and exit if string found
body: <p>I need to grep a continuous output stream from a ping-type output and check for the pattern "EOF" then quit if found.  So far I have used the line buffering mode in grep and also have tried to output to a file, grep the file, but have not been able to get this to work.  Last resort is to ask the community for help.  Ideally I don't want a debug file and just want to have the code execute through pipes and if then statements.<br>
  "Apt-get install hping3" will get the hping3 package.</p>
  
  <p>My current output is a endless stream of "EOF reached, wait some second than press ctrl+c" which is why I am trying to write to script to exit the loop on it's own instead of having to monitor the loop to press ctrl-c.</p>
  
  <pre><code>    #$1 - destination IP
      #$2 - signature
      #$3 - filename
      #$4 - data frame size
      CMD="hping3 $1 --icmp --sign $2 --file $3 -d $4 -u"
      EXP="EOF"
      while true
          do
          $CMD | grep -q --line-buffered -m 1 $EXP &gt; ./debug.txt
              if grep "$EXP" ./debug.txt
              then
              echo "string found"
              fi
      exit
      done
  </code></pre>