title: Quoting not respected inside a bash variable
body: <p>I'm storing the arguments to a command in a variable. The final command I want is:</p>
  
  <pre><code>mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm
  </code></pre>
  
  <p>Here's my attempt:</p>
  
  <pre><code>set -x    # for debugging
  
  RESULTDIR=results
  MOCK_CONFIG="myconfig"
  MOCK_ARGS="-r $MOCK_CONFIG --define \"debug_package %{nil}\" --resultdir $RESULTDIR"
  cmd="mock $MOCK_ARGS --rebuild mypackage.src.rpm"
  $cmd
  </code></pre>
  
  <p>The results are:</p>
  
  <pre><code>+ RESULTDIR=results
  + MOCK_CONFIG=myconfig
  + MOCK_ARGS='-r myconfig --define "debug_package %{nil}" --resultdir results'
  + cmd='mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm'
  + mock -r myconfig --define '"debug_package' '%{nil}"' --resultdir results --rebuild mypackage.src.rpm
  ERROR: Bad option for '--define' ("debug_package).  Use --define 'macro expr'
  </code></pre>
  
  <p>As you can see, the arguments to the <code>--define</code> parameter are not being quoted properly. <code>--define</code> thinks I'm passing it only <code>debug_package</code>, which is incomplete.</p>
  
  <p>I have tried various variations in the quotes when defining <code>MOCK_ARGS</code>, even trying to escape the space between <code>debug_package</code> and <code>%{nil}</code>.</p>
  
  <p>What combination of quotes and/or escapes allows me to build this argument list and execute the command from this script?</p>
  
  <p>EDIT:</p>
  
  <p>The reason I'm storing the resulting command in a variable is because it ends up being passed into a function which does some logging, then executes the command.</p>
  
  <p>Also, I have come across <a href="http://bash-hackers.org/wiki/doku.php/mirroring/bashfaq/050" rel="nofollow noreferrer">this FAQ</a> which suggests I should use arrays instead of a variable. I've begun experimenting with arrays but so far don't have a working solution.</p>