title: Bash escaping spaces in filename, in variable
body: <p>I'm quite new to Bash so this might be something trivial, but I'm just not getting it. I'm trying to escape the spaces inside filenames. Have a look. Note that this is a 'working example' - I get that interleaving files with blank pages might be accomplished easier, but I'm here about the space.</p>
  
  <pre><code>#! /bin/sh
  
  first=true
  i=combined.pdf
  o=combined2.pdf
  for f in test/*.pdf
  do
      if $first; then
          first=false
          ifile=\"$f\"
      else
          ifile=$i\ \"$f\"
      fi
      pdftk $ifile blank.pdf cat output $o
      t=$i
      i=$o
      o=$t
      break
  done
  </code></pre>
  
  <p>Say I have a file called <code>my file.pdf</code> (with a space). I want the ifile variable to contain the string <code>combined.pdf "my file.pdf"</code>, such that pdftk is able to use it as two file arguments - the first one being <code>combined.pdf</code>, and the second being <code>my file.pdf</code>.</p>
  
  <p>I've tried various ways of escaping (with or without first escaping the quotes themselves, etc.), but it keeps splitting <code>my</code> and <code>file.pdf</code> when executing pdftk.</p>
  
  <p>EDIT: To clarify: I'm trying to pass multiple file names (as multiple arguments) in one variable to the pdftk command. I would like it to recognise the difference between two file names, but not tear one file name apart at the spaces.</p>