title: pass a command as an argument to bash script
body: <p>How do I pass a command as an argument to a bash script?
  In the following script, I attempted to do that, but it's not working!</p>
  
  <pre><code>#! /bin/sh
  
  if [ $# -ne 2 ]
  then
      echo "Usage: $0 &lt;dir&gt; &lt;command to execute&gt;"
      exit 1;
  fi;
  
  while read line
  do
      $($2) $line
  done &lt; $(ls $1);
  
  echo "All Done"
  </code></pre>
  
  <p>A sample usage of this script would be</p>
  
  <pre><code>./myscript thisDir echo
  </code></pre>
  
  <p>Executing the call above ought to echo the name of all files in the <code>thisDir</code> directory.</p>