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 c...@case.edu http://tiswww.cwru.edu/~chet/