bug-bash
[Top][All Lists]
Advanced

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

Is typeset -a broken if I initialize?


From: Steven W. Orr
Subject: Is typeset -a broken if I initialize?
Date: Tue, 30 Mar 2004 22:54:38 -0500

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: i386-redhat-linux-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib 
-D_GNU_SOURCE  -O2 -g -pipe -march=i386 -mcpu=i686
uname output: Linux saturn 2.4.20-20.9custom #5 SMP Wed Oct 22 16:06:03 EDT 
2003 i686 athlon i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

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

Description:
        If I declare an array using typeset -a and initialize it I get the 
wrong result.
        But if I either do not use typeset or initialize seperately it works 
fine.

I'd like to understand what's going on here. Is this a bug or is this correct 
behaviour?

Repeat-By:

#! /bin/bash
foo ()
{
    typeset -a i_r=( "${r[@]:-echo .}" )
    echo "i_r = $i_r"
    echo "i_r = ${i_r[*]}"
    for ii in "${i_r[@]}"
    do
        echo $ii
    done
}

typeset -a r
r[0]=Hello
r[1]='Hello goodbye'
r[2]='Just a bunch of words'
foo


Fix:
#! /bin/bash
foo ()
{
    typeset -a i_r
    i_r=( "${r[@]:-echo .}" )
    echo "i_r = $i_r"
    echo "i_r = ${i_r[*]}"
    for ii in "${i_r[@]}"
    do
        echo $ii
    done
}

typeset -a r
r[0]=Hello
r[1]='Hello goodbye'
r[2]='Just a bunch of words'
foo




reply via email to

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