The ${var@A} expansion is defined as follows:

> The expansion is a string in the form of an assignment statement or declare 
> command that, if evaluated, recreates parameter with its attributes and value.

However, if var is a nameref, ${var@A} expands to a declare command for the 
variable that var references, not for var itself. The result of this expansion 
cannot be used to "recreate parameter with its attributes and value". Moreover, 
if the nameref references an array, the initializer in the declare statement is 
incorrect even for the array variable referenced by the nameref: it contains 
the first element of the array, not the entire array.

$ echo $BASH_VERSION
5.3.0(1)-release

$ declare -a array=(1 2 3)
$ declare -n nameref=array

$ echo ${nameref@A}
declare -a array='1'

$ declare -p nameref
declare -n nameref="array"

Similarly for ${var@a}:

$ echo ${nameref@a}
a

I was wondering if you could change the behavior of @a and @A expansions on 
namerefs to match the output 
of declare -p ? My code needs to detect variable types, and t=${var@a} has 
negligible overhead. 
t=${ declare -p var; } is ~4 times slower in my tests, while t=$(declare -p 
var) is about two orders of magnitude slower.

-Mark

Reply via email to