[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
I think bash logic in a loop like : while [ condition] |read somevar is
I think bash logic in a loop like : while [ condition] |read somevar is flawed.
Mon, 23 Dec 2013 23:57:32 +0100
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
Subject: [50 character or so descriptive subject here (for reference)]
Configuration Information [Automatically generated, do not change]:
Compiler: gcc -I/home/abuild/rpmbuild/BUILD/bash-4.2
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-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
[Detailed description of the problem, suggestion, or complaint.]
echo entering while
# listing ten files, to generate some output to count.
ls -1 /usr/bin|head -10 |while read fname
cval=$(( cval +1 ))
echo cval = $cval file = $fname
# one would think cval is now 10. but it is not, contrary to any other
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
I know you think something along those lines, at least thats what I am
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.
[Describe the sequence of events that causes the problem
[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., Pierre Gaston, 2013/12/24
Re: I think bash logic in a loop like : while [ condition] |read somevar is flawed., Greg Wooledge, 2013/12/24
- I think bash logic in a loop like : while [ condition] |read somevar is flawed.,