for loop (bash) with spaces in filenames

I like using for loops in bash, but today I wanted to loop through a bunch of filenames that contained spaces. Thus,

for i in `cat goodones.txt`; do echo $i; done

will actually produce more lines of output than there are lines of input in goodones.txt.

This page had the solution: bash while loops.

while read i; do echo $i; done < goodones.txt

Leave a Reply

You must be logged in to post a comment.