[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ${!variable@operator} does not work for variables without values; i
From: |
Chet Ramey |
Subject: |
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a |
Date: |
Thu, 20 Feb 2020 16:22:04 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 2/19/20 7:46 PM, Arfrever Frehtes Taifersar Arahesis wrote:
> But I am not interested in any ${!varname[@]}, but instead in applying
> @operator transformations.
OK, let's see how these work.
Given the following
VAR2=(aaa bbb)
varname=VAR2
What does
echo ${!varname[@]@Q}
output?
You first have to expand `varname[@]' as an indirect reference. Since
varname is a scalar variable, varname[@] expands to the same thing as
varname, which is VAR2. Now you expand VAR2, which, since VAR2 is an
array variable, is the same as VAR2[0]. That gives you "aaa", so the
output is 'aaa'.
Now, let's look at
echo ${VAR2[@]@Q}
which (obviously) outputs 'aaa' 'bbb'. I don't think I need to go through
how that happens.
Finally, take a look at
echo ${!VAR2[@]@Q}
We go through the same process as before to find the value of VAR2[@],
which turns out to be "aaa bbb" (we flatten it to a string for this
expansion, since we want a variable name). That happens to be an invalid
variable name, since it contains a space, so we get
x6d: line 8: aaa bbb: invalid variable name
Since Eli brought up ${!varname[@]}, I'll mention that special case. That's
an expansion, not a parameter. It's a seemingly minor distinction, but the
expansion is the entire contents of the word between the braces, without an
operator. That's why the above cases work the way they do, and
echo ${!VAR2[@]}
outputs `0 1'.
--
``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/
- ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Arfrever Frehtes Taifersar Arahesis, 2020/02/19
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Arfrever Frehtes Taifersar Arahesis, 2020/02/19
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Arfrever Frehtes Taifersar Arahesis, 2020/02/19
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Eli Schwartz, 2020/02/19
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Arfrever Frehtes Taifersar Arahesis, 2020/02/19
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Greg Wooledge, 2020/02/20
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Eli Schwartz, 2020/02/20
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a,
Chet Ramey <=
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Arfrever Frehtes Taifersar Arahesis, 2020/02/20
- Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Chet Ramey, 2020/02/21
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Chet Ramey, 2020/02/20
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Chet Ramey, 2020/02/20
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Chet Ramey, 2020/02/20
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Chet Ramey, 2020/02/20
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a, Chet Ramey, 2020/02/20