title: Dynamically building a command in bash
body: <p>I am construcing a command in bash dynamically. This works fine:</p>
  
  <pre><code>COMMAND="java myclass"
  ${COMMAND}
  </code></pre>
  
  <p>Now I want to dynamically construct a command that redirectes the output:</p>
  
  <pre><code>LOG="&gt;&gt; myfile.log 2&gt;&amp;1"
  COMMAND="java myclass $LOG"
  ${COMMAND}
  </code></pre>
  
  <p>The command still invokes the java process, but the output is not redirected to myfile.log</p>
  
  <p>Additionally, if I do:</p>
  
  <pre><code>BACKGROUND="&amp;"
  COMMAND="java myclass $BACKGROUND"
  ${COMMAND}
  </code></pre>
  
  <p>The command isn't run in the background.</p>
  
  <p>Any clues on how to get the log redirect, and background bits working? (bash -x shows the commands being constructed as expected)</p>
  
  <p>(In reality, unlike this example, the values of LOG and BACKGROUND are set dynamically)</p>