set variable in while loop?

Dear All,

Can anyone advise why this script isn't run as expected?

===========================
status=0
cat /etc/passwd |
while read line; do
status=1
done

echo $status

it always return 0 , but not 1. why?
anything wrong?

Thanks.

Hi,
I guess it's because the piping makes the while loop variables local, I've seen this before and it behaves the same on my bash, But if You try it the other way round it may work better, just made a change to make clear that it is changed and keep the value:

#!/bin/bash
status=0

while read line; do
true && ((status++))
done <  /etc/passwd 

echo $status

/Lakris