[Top][All Lists]

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

        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

        Run this script:

                set -x
                declare -a f
                ( 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.

        None Known

reply via email to

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