On Wed, Jul 10, 2024 at 09:24:03AM -0400, Chet Ramey wrote: > On 7/4/24 2:51 AM, Emanuele Torre wrote: > > 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 > > OK. Is that a problem? The man page says "when evaluated," and running the > result through `eval' -- properly quoted -- produces the expected results. > If there's an issue with making the expansion eval-safe, let's look at that. > > -- > ``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/ >
I was curious about why it expands to multiple values if IFS is unset or is set to a string that contains at least a ' ' character, but it expands to a single value if IFS is set to any string that does not contain any ' ' characters. There is no obvious explanation for that, so that suggests there is something weird going on with this particular kind of expansion. "${a[@]@A}" o/ emanuele6