title: Executing a dynamically created command with spaces in shell script
body: <p>I have to write a script that generates and executes a command with a variable number of arguments containing file names. These file names may contain spaces, and everything must work fine with or without spaces.</p>
  
  <p>For example, this generated command may look like this :</p>
  
  <pre><code>curl --data-urlencode "js_code@/tmp/some folder/data.txt" http://www.someurl.com
  </code></pre>
  
  <p>If I use a hard coded command and execute it it all runs fine, with and without spaces. If I create the command text in a string variable however, and execute the string contents, it seems the command does not take the quotes into account, using only the first part of the file :</p>
  
  <p>The script (simplified, just imagine the command string is created using complex rules) :</p>
  
  <pre><code>#!/bin/sh
  #prepare
  command="curl --data-urlencode \"param_value@/tmp/some folder/data.txt\" www.someurl.com"
  #execute
  $command
  </code></pre>
  
  <p>The results :</p>
  
  <pre><code>$ ./test.sh
  Warning: Couldn't read data from file ""param_value@/tmp/some", this makes an
  Warning: empty POST.
  curl: (6) Couldn't resolve host 'folder'
  </code></pre>
  
  <p>I tried different things, switching quotes style, using things like exec, but I could'nt get this to work.</p>
  
  <p>Any help would be appreciated</p>
  
  <p>Thanks</p>
  
  <p>Note : I should add all this testing is done on Cygwin. It may be important regarding path syntax.</p>