Reading text files in bash
Reading a text file into bash with a for loop can produce unexpected results if a line in the text file has spaces in it.
If you had a text file with this line in it:
d/NON STUDIO/NON STUDIO105/Cavanaugh_M0228867.jpg
And you were to read it with this simple script:
for i in `cat image.list `;
do
echo $i
done
You would get the following output which is probably not what you wanted:
STUDIO105/Cavanaugh_M0228867.jpg
d/NON
If you use while
instead of for
and unstset the <acronym title="Internal Field Seperator">IFS</acronym>
like this:
while IFS= read line
do
: do whatever with $line
done < FILENAME
You will get the desired output of:
d/NON STUDIO105/Cavanaugh_M0228867.jpg
Subscribe via RSS