bug-bash
[Top][All Lists]
Advanced

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

Bash forgets array values outside of a while loop


From: Joe User
Subject: Bash forgets array values outside of a while loop
Date: Mon, 19 Nov 2001 23:42:19 -0600

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: 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  -D_GNU_SOURCE 
-D_FILE_OFFSET_BITS=64  -I.  -I. -I./include -I./lib -I/usr/include -O3 
-fomit-frame-pointer -pipe -mcpu=pentiumpro -march=i586 -ffast-math 
-fno-strength-reduce
uname output: Linux localhost.localdomain 2.4.14 #1 Thu Nov 15 00:45:38 
CST 2001 i686 unknown
Machine Type: i586-mandrake-linux-gnu

Bash Version: 2.05
Patch Level: 1
Release Status: release

Description:
        Use a while loop to fill an array, and after the while loop,
        bash forgets the values.  I don't think this is how it should
        work.

Repeat-By:
        Run this script:

                #!/bin/sh
                set -x
                declare -a f
                fnum=0
                f[0]=old
                ( for i in 0 1 2 3 4 ; do echo $i ; done ) | 
                        while read f[$fnum]; do echo "address@hidden"; 
fnum=$(($fnum+1)); done
                echo "address@hidden"

        The 'while read' fills up a globally declared array f.  When it
        finishes,       f still holds what it had before the loop.
         However, during the loop, it is modified.  Almost like
        f has scope within the while loop.


Fix:
        None Known



reply via email to

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