title: Best way to pipe a program that reads only one line of input
body: <p>Suppose I have a command cmd1 that reads one line of input from standard input and produces one line of output. I also have another command cmd2 which produces multiple lines of output. How do I pipe these two commands in linux so that cmd1 is executed for each line produced by cmd2? If I simply do:</p>
  
  <pre><code># cmd2 | cmd1
  </code></pre>
  
  <p>cmd1 will take only the first line of output from cmd2, produce one line of output and then close. I know I can use an interpreter like perl to do the job, but I wonder if there's a clean way to do it using bash script only.</p>
  
  <p>Thanks</p>