Strange behavior when mixing indirect expansion and parameter transformation in Bash

77 Views Asked by At

According to this answer, I can check whether an array is indexed or associative as follows:

$ declare -a a
$ declare -A b
$ echo ${a@a}
a
$ echo ${b@a}
A

If I use indirect expansion, however, it doesn't work:

$ var=a
$ echo ${!var@a}

$ var=b
$ echo ${!var@a}

$

Yet, if I initialize the arrays, it now works again:

$ a=()
$ b=()
$ var=a
$ echo ${!var@a}
a
$ var=b
$ echo ${!var@a}
A
$

Is this intended behavior or is it a Bash bug?

$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
[...]
0

There are 0 best solutions below