[Top][All Lists]

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

while loop fails to export changed variable

From: David Cuka
Subject: while loop fails to export changed variable
Date: 20 Dec 2002 09:17:28 -0600

From: Dave Cuka
To: address@hidden
Subject: while loop fails to export changed variable

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: i586-mandrake-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-mandrake-linux-gnu' -DCONF_VENDOR='mandrake' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib -D_GNU_SOURCE  -O3 -fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math -fno-strength-reduce
uname output: Linux slot.cuka.com 2.4.20-0.5mdksmp #1 SMP Thu Nov 28 19:52:31 CST 2002 i686 unknown unknown GNU/Linux
Machine Type: i586-mandrake-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

        It appears to me that the while loop code is failing to "export" the changed value of
        an integer variable although I did not try it on any other type of variable.  The loop
        picks up the proper value from its preceding code, but code after the loop does not
        see the changed changed values.  This is contrary to the operation of the "for" loop.

The following script demonstrates the problem, starting at 7, add three for the "a b c" and one
for the "x", the final value should be 11.  The while loop starts with the proper value for
"addcount" but does not "export" the changed value outside of the loop.  See the output

        let addcount=7
        for x in a b c
                let addcount=$addcount+1
                echo "loop: addcount=$addcount"

        echo "x" | while read x
                let addcount=$addcount+1
                echo "while loop: addcount=$addcount"

        echo "end: addcount=$addcount"
loop: addcount=8
loop: addcount=9
loop: addcount=10
while loop: addcount=11
end: addcount=10

David Cuka <address@hidden>

reply via email to

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