title: repeat pipe command until first command succeeds and second command fails
body: <p>I am trying to figure out how to get my bash script to work. I have a the following command:</p>
  
  <pre><code>curl http://192.168.1.2/api/queue | grep -q test
  </code></pre>
  
  <p>I need it to repeat until the first command in the pipline succeeds (meaning the server responds) and the second command fails (meaning the pattern is not found or the queue is empty). I've tried a number of combinations but just can't seem to get it. I looked at using <code>$PIPESTATUS</code> but can't get it to function in a loop how I want. I've tried all kind of variations but can't get it to work. This is what I am currently trying:</p>
  
  <pre><code>while [[ "${PIPESTATUS[0]}" -eq 0 &amp;&amp; "${PIPESTATUS[1]}" -eq 1 ]]
    do curl http://192.168.1.2 | grep -q regular
    echo "The exit status of first command ${PIPESTATUS[0]}, and the second command ${PIPESTATUS[1]}"
    sleep 5 
  done
  </code></pre>