title: Bash/ZSH - How to deal with filenames with spaces in a for loop (using [@])
body: <p>I'm creating a zsh script that renames files selected in Path Finder on OSX. The script gets an array of paths through applescript. The array items are then processed in a for loop for renaming/moving.
  The array output looks like:</p>
  
  <pre><code>'/Users/bwitime/Downloads/2017-05-17 at 12.08.jpeg', '/Users/bwitime/Downloads/Raspberry Pi - 5 Book Collection.pdf'
  </code></pre>
  
  <p>The script works, except when the filename contains spaces.
  Here's the script:</p>
  
  <pre><code>read -A myFiles &lt; &lt;( /usr/bin/osascript  &lt;&lt;'EOS';
  tell application "Path Finder"
      set finderSelection to {}
      set selectedItems to selection
      repeat with theItem in selectedItems
          set selFile to quoted form of (get POSIX path of (contents of theItem))
          copy selFile to the end of finderSelection
      end repeat
  end tell
  
  return finderSelection
  EOS
  )
  
  
  for i in ${myFiles[@]}
  do
  
      FILE=$(echo "$i" | sed 's:,::g' | sed s:"'"::g)
      DIR="${FILE:h}"
      FILENAME="${FILE:t}"
      FOLDERPREFIX="${FILE:h:t}"
      mv "$FILE" "$DIR/$FOLDERPREFIX-$FILENAME"
  done
  </code></pre>
  
  <p>The $i returns as:</p>
  
  <pre><code>'/Users/bwitime/Downloads/2017-05-17
  at
  12.08.jpeg',
  '/Users/bwitime/Downloads/Raspberry
  Pi
  
  5
  Book
  Collection.pdf'
  </code></pre>
  
  <p>I've already tried setting IFS='\n', but that doesn't work because there are no newlines between files in the array. Also, double quoting has no effect.</p>
  
  <p>How to tackle this problem?</p>