Hi,
This is fine.No news here.
Code:
a=2; for i in $(seq 1 3) ; do echo a=$a; a=1; done; echo a=$a
a=2
a=1
a=1
a=1
But this is unexpected - at least for me!
Code:
a=2; seq 1 3 | while read f; do echo a=$a; a=1; done; echo a=$a
a=2
a=1
a=1
a=2
Looks like "a" is a global variable inside the while loop before the assignment, and a local variable after the assignment. At end, "a" still has the original value.
How can I use a global variable inside the "while" loop ? I want a behavior like the first one that use a "for" loop.