Re: Length gotten from references to an value of an array is always 0

Martin D Kealey <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAN_U6MXM61WX4C_4wDxfkayot4eUbeVoqbAp08bmV2Ai-3x8fA@mail.gmail.com>
On Sat, 27 Dec 2025 at 11:39, Ore Redstone <[email protected]>
wrote:

> I'm using the name reference to get the length of an object from an array,
> but it outputs `0`.
>
> *[…]*$ echo ${#c}   *# Expected result: 1*
> 0
> *[…]*
> $ echo $BASH_VERSION
> 5.2.21(1)-release


This appears to operate correctly in Bash v5.3.0:
```
$ b=(AAAAAA BBBBB CCCC)
$ echo "${#b[2]}"
4
$ declare -ng c=b[2]
$ echo "$c"
CCCC
$ echo "${#c}"
4
$ declare -ng c=b
$ echo "${#c}"
6
$ echo $BASH_VERSION
5.3.0(63)-maint
$ uname -a
Linux secrethostname 6.12.57+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.12.57-1 (2025-11-05) x86_64 GNU/Linux
```

According to README-5.3, in the section details changes between
bash-5.2-release and bash-5.3-alpha:

> hh. Fixed nameref expansion where nameref values are valid length expansion
>     expressions but invalid identifiers.

(Whilst not exactly describing your issue, fixing either issue would have
modified the same code.)

-Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.