title: redirect all output in a bash script when using set -x
body: <p>I have a bash script that has <code>set -x</code> in it. Is it possible to redirect the debug prints of this script and all its output to a file? Ideally I would like to do something like this:</p>
  
  <pre><code>#!/bin/bash
  set -x
  (some magic command here...) &gt; /tmp/mylog
  echo "test"
  </code></pre>
  
  <p>and get the</p>
  
  <pre><code>+ echo test
  test
  </code></pre>
  
  <p>output in /tmp/mylog, not in stdout.</p>