[@]@A weird behaviour when IFS does not contain space
From:
Emanuele Torre
Subject:
[@]@A weird behaviour when IFS does not contain space
Date:
Thu, 4 Jul 2024 08:51:18 +0200
User-agent:
Mutt/2.2.13 (00d56288) (2024-03-09)
Hello.
Normally, ${foo[@]@A} expands to multiple values, that are the arguments
to run a declare command that sets foo to the current value/attributes.
bash-5.2$ a=( abc xyz 123 ); declare -pa result=("${a[@]@A}")
declare -a result=([0]="declare" [1]="-a" [2]="a=([0]=\"abc\" [1]=\"xyz\"
[2]=\"123\")")
bash-5.2$ a=( abc xyz 123 ); echoargs "${a[@]@A}"
$1='declare'
$2='-a'
$3='a=([0]="abc" [1]="xyz" [2]="123")'
Today, I have noticed that if IFS is set to a value that does not
include space, [@]@A will expand to a single value
bash-5.2$ IFS=z a=( abc xyz 123 ); declare -pa result=("${a[@]@A}")
declare -a result=([0]="declare -a a=([0]=\"abc\" [1]=\"xyz\" [2]=\"123\")")
bash-5.2$ IFS=z a=( abc xyz 123 ); echoargs "${a[@]@A}"
$1='declare -a a=([0]="abc" [1]="xyz" [2]="123")'
I don't get why this would happen, so I assume it is probably a weird
bug in bash.
As an aside, [*]@A always expands to the declare command joined by
space, even if the first character of IFS is not space; I think that is
a bit confusing, and surprising, but maybe that is done intentionally:
"intended and undocumented"(?).
o/
emanuele6