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

Advertisements

One thought on “for loop (bash) with spaces in filenames

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s