bug-bash
[Top][All Lists]
Advanced

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

Inconsistent handling of arrays.


From: Aaron Marks
Subject: Inconsistent handling of arrays.
Date: Sat, 2 Jul 2005 23:37:29 +1000

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='lin$uname output: Linux crx 2.6.12 #4 Thu Jun 30
12:33:41 EST 2005 i686 unknown unk$Machine Type: i686-pc-linux-gnu

Bash Version: 3.0
Patch Level: 0
Release Status: release

Description:
        The array handling is inconsistent across global variables and
        local variables. See the Repeat-By for more information.

        While this behaviour can be avoided by using 'local -a ...', it
        is inconsistent and a cause for confusion. Local's (and declare'd
        variables) should at least act like their global undeclared
        counterparts without any options specified.

Repeat-By:
        --BEGIN SCRIPT--

        #!/bin/bash
        somefunc() {
                echo "ARRAY BEHAVIOUR WITH GLOBAL:"
                # proper handling with global
                globvar1=($(ls /))
        #       echo "Contents of globvar1: ${globvar1[@]}"
                echo "Length of globvar1: ${#globvar1}"
                echo "Contents of globvar1[0]: ${globvar1[0]}"

                globvar2=(`ls /`)
        #       echo "Contents of globvar2: ${globvar2[@]}"
                echo "Length of globvar2: ${#globvar2}"
                echo "Contents of globvar2[0]: ${globvar2[0]}"

                echo "INCONSISTENT BAHAVIOUR WITH LOCAL:"
                # inconsistent bahaviour                 local
othervar1=($(ls /))
        #       echo "Contents of othervar1: ${othervar1[@]}"
                echo "Length of othervar1: ${#othervar1}"
                echo "Contents of othervar1[0]: ${othervar1[0]}"

                local othervar2=($(ls /))
        #       echo "Contents of othervar2: ${othervar2[@]}"
                echo "Length of othervar2: ${#othervar2}"
                echo "Contents of othervar2[0]: ${othervar2[0]}"


                echo "PROPER HANDLING, BUT SYNTAX INCONSISTENT WITH
GLOBAL VARS$                # this handles it properly, but the -a
should not be required
                # Local and global variables should at least seem to be treated
                # the same.
                local -a somevar1=(`ls /`)
        #       echo "Contents of somevar1: ${somevar1[@]}"
                echo "Length of somevar1: ${#somevar1}"
                echo "Contents of somevar1[0]: ${somevar1[0]}"

                local -a somevar2=(`ls /`)
        #       echo "Contents of somevar2: ${somevar2[@]}"
                echo "Length of somevar2: ${#somevar2}"
                echo "Contents of somevar2[0]: ${somevar2[0]}"
        }

        somefunc

        --END SCRIPT--




reply via email to

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