On 4/5/25 5:37 PM, Koichi Murase wrote:
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:
OK, so you're asking for a new feature/behavior change. Which is fine, don't get me wrong, but it's a little late in the cycle for bash-5.3.
However, this behavior does not match that of other shells:
OK.
Is this intentional?
Maybe? That was more than 30 years ago.
I'd be happy if the current behavior is fixed.
So to be clear, you're requesting a behavior change so that expanding ${#a[0]}, ${#a[*]}, and ${#a[@]}, where a is a scalar variable, when nounset is enabled, does not result in an unbound variable error. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature