title: why pipe output into a bash function does not work
body: <p>There are many discussions on this: <a href="https://stackoverflow.com/questions/11454343/pipe-output-to-bash-function">Pipe output to bash function</a></p>
  
  <p>I just want to know why:</p>
  
  <pre><code>  #bin/sh
    function myfunc () {
        echo $1
    }
  
    ls -la | myfunc
  </code></pre>
  
  <p>will give empty line. May I ask that why isn't our output of <code>ls</code> not treated as <code>$1</code> as the function? What is the mechanism behind this?</p>
  
  <p>If we try:</p>
  
  <pre><code>  #bin/sh
    function myfunc () {
        i=${*:-$(&lt;/dev/stdin)}
        echo $i
    }
  
    ls -la | myfunc
  </code></pre>
  
  <p>Then we have:</p>
  
  <p><code>
  total 32 drwxr-xr-x 6 phil staff 204 Sep 11 21:18 . drwx------+ 17 phil staff 578 Sep 10 21:34 .. lrwxr-xr-x 1 phil staff 2 Sep 10 21:35 s1 -&gt; t1 lrwxr-xr-x 1 phil staff 2 Sep 10 21:35 s2 -&gt; t2 lrwxr-xr-x 1 phil staff 2 Sep 10 21:35 s3 -&gt; t3 -rwxr-xr-x 1 phil staff 96 Sep 11 21:39 test.sh
  </code></p>
  
  <p>which does not keep the actual format of <code>ls -la</code> (with \n).</p>
  
  <p>What is the correct/proposed way to pass a command output to your function as a parameter as it is?</p>
  
  <p>Thanks</p>
  
  <p><strong>Update +John Kugelman</strong></p>
  
  <pre><code>  #bin/sh
    function myfunc () {
      cat | grep "\-&gt;"  | while read line
      do
          echo $line
      done
  
  
      cat | grep "\-&gt;"  | while read line
      do
          echo "dummy"
      done
        }
  
    ls -la | myfunc
  </code></pre>
  
  <p>This will only print once. What if we would like to use the result twice (store it as a variable possible?)</p>
  
  <p>Thanks,</p>