title: Terminate Bash script dependent on piped output
body: <p>I have written the following shell script:</p>
  
  <pre><code>#!/bin/bash
  
  
  counter=0
  
  while [ $counter -lt 250 ]; do
          perl Cumulative_Percentage.pl TP53.lst T1_endo.maf &gt;&gt; OutFile
          perl Optimize_Panel.pl TP53.LST T1_endo.maf &gt;&gt; TP53.lst 
          let counter=counter+1
  done
  </code></pre>
  
  <p>And it works well. The problem is that it often runs through far more loops than it needs to. The Perl script, Optimize_Panel.pl, prints a single line if the loop should continue or exits without printing if the loop should stop. 
  <strong>I want the while loop to terminate if Optimize_Panel.pl exits instead of printing</strong>... but how? </p>
  
  <p>One possible solution I can imagine is to run </p>
  
  <pre><code>wc TP53.lst
  </code></pre>
  
  <p>at the beginning and end of the loop; first setting it to a variable then checking to see if it had increased then leading it to a premature <strong>done</strong> statement if TP53.lst had not been appended. I'm confident that this could work but it feels clunky and I suspect there is a much simpler way to modify the shell script. </p>
  
  <p>Another way I can think of doing this would be to pipe the output of Optimize_Panel.pl into a temporary file then somehow check to see if that file was empty. </p>
  
  <p>Any ideas?</p>