title: What is the best way to write a wrapper function that runs commands and logs their exit code
body: <p>I currently use this function to wrap executing commands and logging their execution, and return code, and exiting in case of a non-zero return code.</p>
  
  <p>However this is problematic as apparently, it does double interpolation, making commands with single or double quotes in them break the script.</p>
  
  <p>Can you recommend a better way?</p>
  
  <p>Here's the function:</p>
  
  <pre><code>do_cmd()
  {
      eval $*
      if [[ $? -eq 0 ]]
      then
          echo "Successfully ran [ $1 ]"
      else
          echo "Error: Command [ $1 ] returned $?"
          exit $?
      fi
  }
  </code></pre>