title: how to conditionally redirect bash script output
body: <p>I want to control the logging from a bash script. I'm newish to scripting and have inherited a script with this:</p>
  
  <pre><code>LOG_STDOUT=/tmp/stdout.$$
  LOG_STDERR=/tmp/stderr.$$
  exec 3&gt;&amp;1
  exec 4&gt;&amp;2
  exec 1&gt;${LOG_STDOUT}
  exec 2&gt;${LOG_STDERR}
  set -x
  echo $0 $SCRIPTREV starting $(date) &gt;&amp;3
  ...
  echo ERRORMESS &gt; &amp;4
  </code></pre>
  
  <p>The overall redirection can of course controlled by putting the execs in a conditional, but I don't know how to manage the >&amp;3 and >&amp;4 redirection. </p>
  
  <p>What's a good way to handle this, so the log files usually collect all the output from -x, but optionally allowing me to have all output go to console? </p>
  
  <p>Thanks</p>