Isn't the issue the pipe, not while?
export a=0
while read line ; do
a=$(expr $a + 1)
done < $file
echo $a
(Some old shells fork on < but bash isn't one of them).