Computing.Net > Forums > Unix > unix while loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix while loop

Reply to Message Icon

Name: gmatsoon
Date: June 17, 2008 at 16:07:33 Pacific
OS: linux and aix
CPU/Ram: 1+Gb
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 17, 2008 at 21:42:44 Pacific
Reply:


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"


0

Response Number 2
Name: gmatsoon
Date: June 18, 2008 at 09:29:37 Pacific
Reply:

That worked.

Thank you for the answer as well as the explanation.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: unix while loop

While loop stuck www.computing.net/answers/unix/while-loop-stuck/6389.html

Using while loop to read a file www.computing.net/answers/unix/using-while-loop-to-read-a-file/7092.html

AWK in a while loop www.computing.net/answers/unix/awk-in-a-while-loop/6669.html