[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [@]@A weird behaviour when IFS does not contain space
From: |
Emanuele Torre |
Subject: |
Re: [@]@A weird behaviour when IFS does not contain space |
Date: |
Wed, 10 Jul 2024 15:42:10 +0200 |
User-agent: |
Mutt/2.2.13 (00d56288) (2024-03-09) |
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 chet@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