title: Run command with space characters in bash script
body: <p>I have a file that contains a list of files:</p>
  
  <pre><code>02 of Clubs.eps
  02 of Diamonds.eps
  02 of Hearts.eps
  02 of Spades.eps
  ...
  </code></pre>
  
  <p>I am attempting to mass-convert these to png format in several sizes. The script I am using to do this is:</p>
  
  <pre><code>while read -r line
  do
      for i in 80 35 200
      do
          convert $(sed 's/ /\\ /g' &lt;&lt;&lt; Cards/${line}) -size ${i}x${i} ../img/card/$(basename $(tr ' ' '_' &lt;&lt;&lt; ${line} | tr '[A-Z]' '[a-z]') .eps)_${i}.png;
      done
  done &lt; card_list.txt
  </code></pre>
  
  <p>However, this doesn't work, apparently trying to split on each word, resulting in the following error output:</p>
  
  <pre><code>convert: unable to open image `Cards/02\': No such file or directory @ error/blob.c/OpenBlob/2514.
  convert: no decode delegate for this image format `Cards/02\' @ error/constitute.c/ReadImage/532.
  convert: unable to open image `of\': No such file or directory @ error/blob.c/OpenBlob/2514.
  convert: no decode delegate for this image format `of\' @ error/constitute.c/ReadImage/532.
  convert: unable to open image `Clubs.eps': No such file or directory @ error/blob.c/OpenBlob/2514.
  </code></pre>
  
  <p>If I change the convert to an echo the result looks right and if I copy a line and run it myself in the shell it works fine:</p>
  
  <pre><code>convert Cards/02\ of\ Clubs.eps -size 80x80 ../img/card/02_of_clubs_80.png
  convert Cards/02\ of\ Clubs.eps -size 35x35 ../img/card/02_of_clubs_35.png
  convert Cards/02\ of\ Clubs.eps -size 200x200 ../img/card/02_of_clubs_200.png
  convert Cards/02\ of\ Diamonds.eps -size 80x80 ../img/card/02_of_diamonds_80.png
  convert Cards/02\ of\ Diamonds.eps -size 35x35 ../img/card/02_of_diamonds_35.png
  convert Cards/02\ of\ Diamonds.eps -size 200x200 ../img/card/02_of_diamonds_200.png
  convert Cards/02\ of\ Hearts.eps -size 80x80 ../img/card/02_of_hearts_80.png
  convert Cards/02\ of\ Hearts.eps -size 35x35 ../img/card/02_of_hearts_35.png
  convert Cards/02\ of\ Hearts.eps -size 200x200 ../img/card/02_of_hearts_200.png
  convert Cards/02\ of\ Spades.eps -size 80x80 ../img/card/02_of_spades_80.png
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Just adding quotes (see below) has the same result as the above, where I had been using sed to add backslashes</p>
  
  <pre><code>convert '"'Cards/${line}'"' -size ${i}x${i} ../img/card/$(basename $(tr ' ' '_' &lt;&lt;&lt; ${line} | tr '[A-Z]' '[a-z]') .eps)_${i}.png;
  </code></pre>
  
  <p>I've tried both double and single quotes</p>