tags:

views:

180

answers:

2

I'm parsing som .html files in bash. I read the in with:

while read line 
do
   echo $line
   ..do something...
done < $file

Now I've expierenced sth. real strange. Some lines in the files contain sth. like

Resolution…: 720 * 576

But bash gives me this:

Resolution…: 720 mysript.sh another_script.pl 576

Bash expands the * char to the content of the actual directory. How can I read the text line by line without expanding the ' thanks in advance

+4  A: 

the expanding happens in echo, not in read, you should quote your output:

echo "$line"
catwalk
Thanks very much, I've been blind
cb0
+1  A: 

you should read your file like this, with the -r option

while read -r line 
do
   echo "$line"
   #..do something...
done < "$file"
This is a good practice, but it solves a different problem: it turns off backslash interpretation (e.g. without it, read will treat a backslash at the end of an input line as a continuation marker).
Gordon Davisson