bug-bash
[Top][All Lists]
Advanced

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

while loop read file problem


From: ___紸角...
Subject: while loop read file problem
Date: Sat, 6 Dec 2014 02:57:03 +0800

HI:
one way:
#!/usr/bin/bash
a=0
FILE="myfile.txt"
cat $FILE | while read line
do
a=$(($a+1))
echo $a
#done < $FILE
done
echo "Final line count is: $a

two way:
#!/usr/bin/bash

a=0
FILE="myfile.txt"
 while read line
do
a=$(($a+1))
echo $a
done < $FILE

echo "Final line count is: $a"


On the one way: the variable $a  in while loop is not useful. The two way excute result is not equal




------------------
                                             


                                                               谢谢!     
                                                       崔志良
 

reply via email to

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