title: How to cope with spaces in file names when iterating results from git diff --name-only
body: <p>A script I am working on needs to go through each file from a git diff. However, I don't know how to deal with spaces in the file name. Any files that have a space are split into "2 files". I know they need to be wrapped in <code>" "</code> but I don't know how to achieve that before it goes to the <code>@</code> param. </p>
  
  <p><strong>When there are spaces in filenames, how should I iterate over the files from</strong></p>
  
  <pre><code>git diff --name-only  $1
  </code></pre>
  
  <p><strong>?</strong> </p>
  
  <p>Here is a simple test that reproduces the error:</p>
  
  <pre><code>copyfiles()
  {
      echo "Copying added files"
      for file in $@; do
  
          new_file=$(echo ${file##*/})
  
          directory=$(echo ${file%/*})
          echo "Full Path is is  $file"
          echo "File is  $new_file"
          echo "Directory is  $directory"
          cp $file $COPY_TO
      done    
  }
  
  COPY_TO="testDir"
  DIFF_FILES=$( git diff --name-only  $1) 
  copyfiles $DIFF_FILES 
  </code></pre>
  
  <p>The script is currently run like:   </p>
  
  <pre><code>test.sh &lt;git commit id&gt;
  </code></pre>