title: Bash: using function with pipe as argument for another function
body: <p>I'm trying to make function-wrapper for another functions to distinguish its in terminal</p>
  
  <pre><code>red_line="$(tput setaf 1)## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## $(tput sgr 0)"
  
  function wrapper {
      echo $red_line;
      echo "$(tput setaf 1)## $(tput setab 7)$(tput setaf 0)$1 $(tput sgr 0)";
      $2;
      echo $red_line;
  }
  
  function foo {
      wrapper "custom command description" "ps axo pid,stat,pcpu,comm | tail -n 10;"
  }
  </code></pre>
  
  <p>but error was occurred: <code>ps: illegal argument: |</code></p>
  
  <p>I've tried to use <code>$(ps ... | tail -n 10)</code> and backticks instead of string and then print out result in wrapper with <code>echo $2</code>, but caught another errors</p>
  
  <p>Also tried <code>"eval $(ps ... | tail -n 10)"</code> and it also didn't work.</p>
  
  <p>Everything works just fine w/o wrapper:</p>
  
  <pre><code>function pss {
      echo $red_line
      echo "$(tput setaf 1)## $(tput setab 7)$(tput setaf 0)formatted 'ps ax' command $(tput sgr 0)"
  
      ps axo pid,stat,pcpu,comm | tail -n $1;
  
      echo $red_line
  }
  </code></pre>
  
  <p><a href="http://i.imgur.com/eLUqQPk.jpg" rel="nofollow">result screenshot</a></p>