title: Use output of bash command (with pipe) as a parameter for another command
body: <p>I'm looking for a way to use the ouput of a command (say command1) as an argument for another command (say command2).</p>
  
  <p>I encountered this problem when trying to <code>grep</code> the output of <code>who</code> command but using a pattern given by another set of command (actually <code>tty</code> piped to <code>sed</code>).</p>
  
  <h2>Context:</h2>
  
  <p>If <code>tty</code> displays:</p>
  
  <pre><code>/dev/pts/5
  </code></pre>
  
  <p>And <code>who</code> displays:</p>
  
  <pre><code>root     pts/4        2012-01-15 16:01 (xxxx)
  root     pts/5        2012-02-25 10:02 (yyyy)
  root     pts/2        2012-03-09 12:03 (zzzz)
  </code></pre>
  
  <h2>Goal:</h2>
  
  <p>I want only the line(s) regarding "pts/5"
  So I piped <code>tty</code> to <code>sed</code> as follows:</p>
  
  <pre><code>$ tty | sed 's/\/dev\///'
  pts/5
  </code></pre>
  
  <h2>Test:</h2>
  
  <p>The attempted following command doesn't work:</p>
  
  <pre><code>$ who | grep $(echo $(tty) | sed 's/\/dev\///')"
  </code></pre>
  
  <h2>Possible solution:</h2>
  
  <p>I've found out that the following works just fine:</p>
  
  <pre><code>$ eval "who | grep $(echo $(tty) | sed 's/\/dev\///')"
  </code></pre>
  
  <p><strong>But I'm sure the use of <code>eval</code> could be avoided.</strong></p>
  
  <p><em>As a final side node: I've noticed that the "-m" argument to <code>who</code> gives me exactly what I want (get only the line of <code>who</code> that is linked to current user). But I'm still curious on how I could make this combination of pipes and command nesting to work...</em></p>