bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I think bash logic in a loop like : while [ condition] |read somevar


From: rens
Subject: Re: I think bash logic in a loop like : while [ condition] |read somevar is flawed.
Date: Tue, 24 Dec 2013 09:25:05 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

*
**=>which read**
**which: no read in (/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin)**
**3


*read is a built in. there is no  subshell.
any way, it seems then to me that even IF "read" was a subshell, the scope of that would start and end with the read statement.
as you can see, it is not true.
it extends to the scope of the entire while loop, as the "echo cval" statements demonstrate....

thus, magically read in the subshell is making while a part of it's own shell ???

there is no "while|read"  command, you see.....

so "while" also invokes a shell ? that magically can do which you think is not possible ??
because it is then the parent, not a child, evidently ?

please explain......



Really, all other programming languages propagate variables from
children to parents? I find that hard to believe.






that makes no sense.
there  is no read command in my path.

so, with that out of the way, what is your comment ?


On 12/24/13 08:04, Chris Down wrote:
On 2013-12-23 23:57:32 +0100, rens wrote:
Hello,

this script:
_______________________
export cval=0
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.

do
cval=$(( cval +1 ))
echo cval = $cval  file = $fname
done
# one would think cval is now 10. but it is not, contrary to any other
programming language........
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
technically work.
I know you think something along those lines, at least thats what I am
told....
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...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]