unix while loop

June 17, 2008 at 16:07:33
Specs: linux and aix, 1+Gb
I have 3 files in a directory. The files are named as below


The file filename.txt contains the following 1 line


When I run the following while loop I get the following output

while read r
echo $r
done < filename.txt

Output is


I would have expected the output to be

What am I doing wrong?

See More: unix while loop

Report •

June 17, 2008 at 21:42:44

When the echo command executes, the astric is treated as a meta character. The expansion says to list all files in the current directory that end with DOS.

To prevent the expansion, surround the variable with quotes:

echo "$r"

Report •

June 18, 2008 at 09:29:37
That worked.

Thank you for the answer as well as the explanation.

Report •

Related Solutions

Ask Question