The pipe forces the loop block to run in a sub shell.
Variables and settings in a sub shell are not copied back to the main shell.
All shells (bash,ksh,zsh,dash,mksh) agree in that.
More precise: the code parts left and right from a pipe are forced into a sub shell.
The only exception is ksh: it runs the
last part in the main shell:
Code:
failed=0
echo "hello" |
while read line; do
echo "FAILED"
failed=1
done
echo "Failed: $failed"
Only ksh says:
BTW this proves that mksh, despite its name, is more a Posix shell than a ksh.