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



Post comment