title: Can I pass an arbitrary block of commands to a bash function?
body: <p>I am working on a bash script where I need to conditionally execute some things if a particular file exists.  This is happening multiple times, so I abstracted the following function:</p>
  
  <pre><code>function conditional-do {
      if [ -f $1 ]
      then
          echo "Doing stuff"
          $2
      else
          echo "File doesn't exist!"
      end
  }
  </code></pre>
  
  <p>Now, when I want to execute this, I do something like:</p>
  
  <pre><code>function exec-stuff {
      echo "do some command"
      echo "do another command"
  }
  conditional-do /path/to/file exec-stuff
  </code></pre>
  
  <p>The problem is, I am bothered that I am defining 2 things: the function of a group of commands to execute, and then invoking my first function.</p>
  
  <p>I would like to pass this block of commands (often 2 or more) directly to "conditional-do" in a clean manner, but I have no idea how this is doable (or if it is even possible)... does anyone have any ideas?</p>
  
  <p>Note, I need it to be a readable solution... otherwise I would rather stick with what I have.</p>