title: pass parameters to a user defined function called by xargs
body: <p>I have an array "foo". I want to pass the array to a self-defined function "bar" which is part of the xargs command. It takes me sometime to figure out how to invoke a user defined function in xargs. To achieve that, I export the function "bar" and use "bash -c" to execute it. However the $foo cannot be passed to bar(). $1 in bar() is empty.</p>
  
  <p>Does anyone know how to solve this?</p>
  
  <p>Thanks!!</p>
  
  <pre><code>foo="1 2 3 4 5 6 7 8 9"
  
  bar(){
     echo $1
     echo "asdf"
     sleep 2
  }
  
  export -f bar
  
  echo $foo | xargs -n 1 -P 3 bash -c bar
  </code></pre>