Shell Script Spaces in Filenames

I was using a for loop to read the filenames in a directory but received errors on files with spaces in the names. For future reference the following worked:

#!/bin/bash

ls -1 | while read FILE; do
echo “$FILE” # double quotes needed for filename with spaces!
done

exit 0

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>