Hello, a strange behaviour of while with bash 4.0.28 :
Code:
$ A=1 ; while [ $A -lt 4 ] ; do A=$((A+1)); echo $A ; done ; echo $A
2
3
4
4
Code:
$ A=1 ; cat foobar |while [ $A -lt 4 ] ; do A=$((A+1)); echo $A ; done ; echo $A
2
3
4
1
My first question : after a pipe,
while does'nt keep the value for variable $A. Why ?
My second question : dash behaves like bash, but zsh and ksh have a more "normal" behaviour : the 2 variants end with $A=4.
Is there a good reason ? Posix compatibility or somewhat ?
(
foobar is a real file, but it's the same if it doesn't exist)