On 3/20/14 12:41 AM, Richard Tollerton wrote:
>
> Old behavior, bash 4.2.45:
>
> $ bash -c 'set -u; echo ${#arr1[@]}'; \
> bash -c 'set -u; declare var1; echo ${#var1}'; \
> bash -c 'set -u; declare -a arr2; echo ${#arr2[@]}'
> bash: arr1: unbound variable
> bash: var1: unbound variable
> 0
>
> New behavior, bash 4.3:
>
> $ bash -c 'set -u; echo ${#arr1[@]}'; \
> bash -c 'set -u; declare var1; echo ${#var1}'; \
> bash -c 'set -u; declare -a arr2; echo ${#arr2[@]}'
> bash: arr1: unbound variable
> bash: var1: unbound variable
> bash: arr2: unbound variable
>
> I suppose that this change in behavior makes array variables more
> consistent with normal variables, but I couldn't find anything in
> CHANGES which obviously relates to this, so I'm not sure if this is a
> bug or not.
There is this, in the list of changes in bash-4.3-beta:
f. Fixed several cases where `invisible' variables (variables with attributes
but no values, which are technically unset) were treated incorrectly.
> Was I always mistaken in figuring that declaring an array also
> initialized it?
A variable is not set until it has been assigned a value. This was always
true, and always supposed to apply to array variables as it did to scalars.
bash-4.2 had a number of inconsistencies here, and I fixed some number of
those. I'm sure some still remain.
This topic has come up several times in the past, most recently a couple
of weeks ago:
http://lists.gnu.org/archive/html/bug-bash/2013-01/msg00068.html
http://lists.gnu.org/archive/html/bug-bash/2013-11/msg00000.html
http://lists.gnu.org/archive/html/bug-bash/2014-03/msg00052.html
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/