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

2013-12-23 Thread rens


Subject: [50 character or so descriptive subject here (for reference)]

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.2 
-L/home/abuild/rpmbuild/BUILD/bash-4.2/../readline-6.2
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu' 
-DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -g -D_GNU_SOURCE 
-DRECYCLES_PIDS -Wall -g -std=gnu89 -Wuninitialized -Wextra 
-Wno-unprototyped-calls -Wno-switch-enum -Wno-unused-variable 
-Wno-unused-parameter -ftree-loop-linear -pipe -fprofile-use
uname output: Linux dep2.fritz.box 3.7.10-1.16-default #1 SMP Fri May 31 
20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux

Machine Type: x86_64-suse-linux-gnu

Bash Version: 4.2
Patch Level: 42
Release Status: release
 bug-bash@gnu.org
Description:
[Detailed description of the problem, suggestion, or complaint.]

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
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


echo  " after while: cval = $cval"
___

does not set the value of cval after exiting the while loop.

that makes no sense.

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


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.


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.


Thank you for your willingness to open up your trench line, if any.

best regards,

Rens




Repeat-By:
[Describe the sequence of events that causes the problem
to occur.]

Fix:
[Description of how to fix the problem.  If you don't know a
fix for the problem, don't include this section.]




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

2013-12-23 Thread Chris Down
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...


pgp6pXgFwKge0.pgp
Description: PGP signature


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

2013-12-23 Thread Pierre Gaston
On Tue, Dec 24, 2013 at 12:57 AM, rens  wrote:

>
> Subject: [50 character or so descriptive subject here (for reference)]
>
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.2
> -L/home/abuild/rpmbuild/BUILD/bash-4.2/../readline-6.2
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-suse-linux-gnu'
> -DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -fmessage-length=0
> -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables
> -fasynchronous-unwind-tables -g -D_GNU_SOURCE -DRECYCLES_PIDS -Wall -g
> -std=gnu89 -Wuninitialized -Wextra -Wno-unprototyped-calls -Wno-switch-enum
> -Wno-unused-variable -Wno-unused-parameter -ftree-loop-linear -pipe
> -fprofile-use
> uname output: Linux dep2.fritz.box 3.7.10-1.16-default #1 SMP Fri May 31
> 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-suse-linux-gnu
>
> Bash Version: 4.2
> Patch Level: 42
> Release Status: release
>  bug-bash@gnu.org
> Description:
> [Detailed description of the problem, suggestion, or complaint.]
>
> 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
> 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
>
> echo  " after while: cval = $cval"
> ___
>
> does not set the value of cval after exiting the while loop.
>
> that makes no sense.
>
> 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
>
> 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.
>
> 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.
>

Actually only ksh93 doesn't work this way, other "ksh" variants work like
bash.
In newer bash you can do, if job control is disable (that is in a script):
shopt -s lastpipe.

Note that even with this, only the right hand side doesn't run in a forked
subshell, eg in ksh93 or bash with last pipe:
var=foo | true;echo $var # prints nothing

At least one side of the pipe has to be in a child process.
The same thing is true if you use a pipe and fork a process in these other
languages you mention.


Re: soft-bug (should be in planning queue)...

2013-12-23 Thread Chris Down
On 2013-12-21 14:13:25 -0800, Linda Walsh wrote:
> Did you mean july 2013?

Probably not, plenty of 4.3 code is not being backported.


pgprkzu2zkgSh.pgp
Description: PGP signature