Re: while loop read file problem

2014-12-06 Thread Eduardo A . Bustamante López
This is well know, and not a bug. Please read: http://mywiki.wooledge.org/BashFAQ/024 when you run: command | while-loop the 'while-loop' part is executed in a subshell (actually, both commands are). This means that they're no longer the same process as the main shell, and the consequence is tha

while loop read file problem

2014-12-06 Thread ___紸角...
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