bash while read question

Evuraan evuraan at gmail.com
Thu May 6 01:25:47 UTC 2010


I cant figure out why the variable in in loop2 does not hike to +1?
(its a friday, i am dazed, I admit. but this should not be a mystery!)
any help would be much appreciated.


$ cat loop1
#! /bin/bash

date > /tmp/somefile
b="1"
while read blah; do
let b=(b+1)
done  < /tmp/somefile
echo "variable is $b"

$ cat loop2
#! /bin/bash

date > /tmp/somefile
b="1"
cat /tmp/somefile | while read blah; do
let b=(b+1)
done
echo "variable is $b"


$ ./loop1
variable is 2

$ ./loop2
variable is 1


More information about the freebsd-questions mailing list