On 2013-12-23 23:57:32 +0100, rens wrote:
echo entering while
# listing ten files, to generate some output to count.
ls -1 /usr/bin|head -10 |while read fname
Just use a `for` loop and a glob. Really. It's that easy.
cval=$(( cval +1 ))
echo cval = $cval file = $fname
# one would think cval is now 10. but it is not, contrary to any other
Really, all other programming languages propagate variables from
children to parents? I find that hard to believe.
that makes no sense.
Yes, it does. You created a subshell. How do you expect for the variable
to propagate back to the parent, where you are expanding it?
Please Don't bother to tell me it s the way you guys think it should
I know you think something along those lines, at least thats what I am
Don't use a subshell if you don't want one.
However, no one in this world having to solve real life issues with
software, is interested in how it technically works. we need real life
logic and software that can deal with real life challenges and requirements.
Then stop using a subshell.
Bash should not work that way. no programming language handles logic this
way. Not pascal, korn shell, c shell, cobol, c, c++, lua , fortran or any
other language i ever used.
None of the languages you listed propagate variables from children to
parents directly. I don't know why you think you should have that
variable in the parent when you populated it in a subshell...