bug-bash
[Top][All Lists]
Advanced

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

array variables set in while loop not known outside loop


From: David P. Kitzinger
Subject: array variables set in while loop not known outside loop
Date: Thu, 08 Aug 2002 11:32:13 -0600

From: dkitzing@ara.com
To: bug-bash@gnu.org
Subject: array variables set in while loop not known outside loop

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: i686-pc-cygwin-gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I../bash-2.05a -I../bash-2.05a/include 
-I../bash-2.05a/lib -g -O2
uname output: CYGWIN_98-4.10 STRIDER 1.3.10(0.51/3/2) 2002-02-25 11:14 i686 
unknown
Machine Type: i686-pc-cygwin

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

Description:
        I read in values into an array variable inside a while loop.
        Outside the while loop, no knowledge of these assignments is known.

Repeat-By:
        Run the following in a script file:

declare -a bf
i=1
echo "XXX
YYY" | while read X
do
    bf[i]="$X"
    echo "set element $i to ${bf[i]}"
    ((i = i + 1))
done

echo "number of elements: ${#bf[*]}"
echo "element 1 is: ${bf[1]}"

----------end of script content--------

(incorrect) output is:

set element 1 to XXX
set element 2 to YYY
number of elements: 0
element 1 is: 

(correct) output should be:

set element 1 to XXX
set element 2 to YYY
number of elements: 2
element 1 is: XXX





reply via email to

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