[Top][All Lists]

[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

From: rens
Subject: I think bash logic in a loop like : while [ condition] |read somevar is flawed.
Date: Mon, 23 Dec 2013 23:57:32 +0100
User-agent: 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]:
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
    [Detailed description of the problem, suggestion, or complaint.]


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
cval=$(( cval +1 ))
echo cval = $cval  file = $fname
# 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,


    [Describe the sequence of events that causes the problem
    to occur.]

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

reply via email to

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