title: Quoting in a bash variable assignment
body: <p>Using the following simplified code extract:</p>
  
  <pre><code>DIR='a b'
  mount_command="./mount.cpfs $loop $DIR -f $OPTS"
  sudo $mount_command
  </code></pre>
  
  <p>Executes this line when trace is on:</p>
  
  <pre><code>+ sudo ./mount.cpfs /dev/loop0 a b -f -o default_permissions,allow_other,attr_timeout=0
  </code></pre>
  
  <p>But <code>DIR</code> is not quoted, and so <code>a</code> and <code>b</code> are passed as different parameters, rather than the same to <code>./mount.cpfs</code>.</p>
  
  <p><strong>What's the best way to go about creating a command sequence like this, and then expanding it into a later command line?</strong></p>
  
  <p>Please keep in mind the code example is simplified to the core problem, I'm using <code>mount_command</code> in several places with various additions before and after it, and <code>DIR</code> is passed in by the user. I've tried several combinations of quoting <code>DIR</code> when assigning to <code>mount_command</code>, and a primitive attempt at using an array.</p>
  
  <h2>Example Usage of <code>mount_command</code></h2>
  
  <pre><code>mount_command="./mount.cpfs $loop $DIR -f $OPTS"
  case "$MODE" in
      gdb)
          sudo gdb -return-child-result -x gdbbatch \
              --args $mount_command
          ;;
      normal)
          sudo $mount_command
          ;;
      valgrind)
          sudo valgrind --track-fds=yes --leak-check=full --malloc-fill=0x80 \
              --free-fill=0xff $mount_command
          ;;
      *)
          echo "Mode '$MODE' unknown"
          mounted=''
          exit 2
          ;;
  esac
  </code></pre>
  
  <h2>Update0</h2>
  
  <p>Please test your suggestions, I don't think the solution is straightforward.</p>