bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with reading file and executing other stuffs?


From: Horinius
Subject: Problem with reading file and executing other stuffs?
Date: Thu, 1 Nov 2007 12:32:07 -0700 (PDT)

I've been struggling with the following code of reading a text file
(test.txt) and counting the number of lines.  Well, I know there're simpler
method to count the number of lines of a text file, but that's not the point
of this post.
__________

n=0
cat test.txt | 
while read line
do
        n=$((n+1))
        echo "${line}"
done

echo "$n"
__________

The result of the last echo is zero, meaning that n is never incremented
inside the while loop.  It seems to me that inside this while loop, except
the echo of the lines, nothing else is done.

Pitfall? Bug?  Or feature?

I'd appreciate if somebody could shed some light on this.

-- 
View this message in context: 
http://www.nabble.com/Problem-with-reading-file-and-executing-other-stuffs--tf4733602.html#a13535762
Sent from the Gnu - Bash mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]