title: How can I print each command before executing?
body: <p>What is the best way to set up a Bash script that prints each command before it executes it?</p>
  
  <p>That would be great for debugging purposes.</p>
  
  <p>I already tried this:</p>
  
  <pre><code>CMD="./my-command --params &gt;stdout.txt 2&gt;stderr.txt"
  echo $CMD
  `$CMD`
  </code></pre>
  
  <p>It's supposed to print this first:</p>
  
  <pre><code>./my-command --params &gt;stdout.txt 2&gt;stderr.txt
  </code></pre>
  
  <p>And then execute <code>./my-command --params</code>, with the output redirected to the files specified.</p>