Madduck, the thing you're not seeing in your examples, which is pretty painfully obvious to people who do write a lot of shell code is that the shell starts a subshell for any shell code on the right hand side of a pipeline. So when you do:
echo -e "1\n2\n3" | while read i; do
blah
done
You're running the whole while loop (not just its body) in a subshell, just as if you'd written:
echo -e "1\n2\n3" | (
while read i; do
blah
done
)
This is indeed occasionally annoying.
(BTW, any posix shell will behave the same way. I'm suprised zsh doesn't, but then I don't generally write significant code for zsh since it's so different.)
(PPS, can I delete Biella's drive now?)
Add a comment