With nounset, ${#a[@]} for a scalar variable fails even though we can
correctly obtain the result (which is consistent with the expansion of
"${a[@]}") without nounset. This is the result with the devel
version:
$ bash -c 'a=1; echo ${#a[@]}'
1
$ bash -uc 'a=1; echo ${#a[@]}'
bash: line 1: a: unbound variable
This behavior seems to be present from the very beginning
implementation of arrays in bash-2.0:
$ bash-2.0 -c 'a=1; echo ${#a[@]}'
1
$ bash-2.0 -uc 'a=1; echo ${#a[@]}'
bash-2.0: a: unbound variable
However, this behavior does not match that of other shells:
$ ksh -c 'a=1; echo ${#a[@]}'
1
$ ksh -uc 'a=1; echo ${#a[@]}'
1
$ mksh -c 'a=1; echo ${#a[@]}'
1
$ mksh -uc 'a=1; echo ${#a[@]}'
1
$ zsh -c 'a=1; echo ${#a[@]}'
1
$ zsh -uc 'a=1; echo ${#a[@]}'
1
Is this intentional? If so, how can I understand the mental model or
the design background? I'd be happy if the current behavior is fixed.
--
Koichi