title: How to jump the infinite while loop when all data read out of the pipe?
body: <pre><code>cat  pipe.sh
  #！/bin/bash
  fifo_file=fifo.pipe
  mkfifo $fifo_file
  exec 6&lt;&gt;$fifo_file
  rm $fifo_file
  
  DateWrite ()
  {
      i=0
      while [ $i -lt 100 ]
      do
          str=`date`
          i=$(( i+1 ))
          echo "$i $str"
      done
  }
  
  for  (( i=0; i&lt;10; i++ ))
  do 
       ( DateWrite &gt;&amp;6 ) &amp;
  done
  while read date_time
  do
      echo $date_time &gt;&gt; output.file
  done &lt;&amp;6
  </code></pre>
  
  <p>The above bash code create a named pipe,<code>DateWrite</code> function write a string in pipe,it create a 10 process with for loop ,read data from pipe with while loop.<br>
  <code>bash pipe.sh</code> can't stop,it enter into a infinite while loop.<br>
  How to jump the while loop when all data read out of the pipe?<br>
  Another issue:Why <code>rm $fifo_file</code> after <code>exec 6&lt;&gt;$fifo_file</code>?</p>
  
  <p>Try as @chepner say:</p>
  
  <pre><code>vim pipe.sh
  #！/bin/bash
  fifo_file=fifo.pipe
  mkfifo $fifo_file
  exec 6&lt;&gt;$fifo_file
  rm $fifo_file
  
  DateWrite ()
  {
      i=0
      while [ $i -lt 100 ]
      do
          str=`date`
          i=$(( i+1 ))
          echo "$i $str"
      done
  }
  
  writers=()
  for  (( i=0; i&lt;10; i++ ))
  do 
       ( DateWrite &gt;&amp;6 ) &amp; writers+=($!)
  done
  
  while read date_time
  do
      echo $date_time &gt;&gt; output.file
  done &lt;&amp;6 &amp;
  
  for writer in "${writers[@]}"; do
    wait "$writer"
  done
  
  exec 6&gt;&amp;-
  </code></pre>
  
  <p>It works fine.
  There are two lines here i don't understand.</p>
  
  <pre><code>writers=()
   ( DateWrite &gt;&amp;6 ) &amp; writers+=($!)
  </code></pre>
  
  <p>What does it mean?</p>