Articles

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

MSDOS
PCDOS
filename.txt

The file filename.txt contains the following 1 line

*****DOS

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

while read r
do
echo $r
done < filename.txt

Output is

MSDOS PCDOS

I would have expected the output to be
****DOS.

What am I doing wrong?


See More: unix while loop

Report •


#1
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 •

#2
June 18, 2008 at 09:29:37

That worked.

Thank you for the answer as well as the explanation.


Report •

Related Solutions


Ask Question