Handling Filenames with Spaces in Bash

http://www.macgeekery.com/tips/cli/handling_filenames_with_spaces_in_bash

If you set IFS to $’n’ then it will only split on newlines, not spaces. And you can enclose the entire thing in a subshell using ( foo ) to scope IFS to just that for loop.

Example:

(
IFS=$’n’
for file in $files
do
echo “$file” rocks.
done
)

Leave a Reply

Your email address will not be published. Required fields are marked *