Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15947
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a |
| Date | 2020-02-21 09:37 -0500 |
| Message-ID | <mailman.1362.1582295859.2412.bug-bash@gnu.org> (permalink) |
| References | (3 earlier) <fef87d32-6e48-f10d-8b3b-b794c5940a51@archlinux.org> <CALaCa4wT=ZegSUtzCMsy1tKW9=D6sgvk8HDB=UkB+X3_31ApoA@mail.gmail.com> <3087dce5-4d60-4cd9-88d3-318693bf87af@case.edu> <CALaCa4zTgpJMEHB-6ErEDTbQdEwcCVR0Khrjn6XPPECi7XGpgw@mail.gmail.com> <5b441f49-44e2-9ea2-8a84-d8223ac1dd84@case.edu> |
On 2/20/20 6:54 PM, Arfrever Frehtes Taifersar Arahesis wrote:
> Chet Ramey <chet.ramey@case.edu> 2020-02-20 21:22 UTC:
>> 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'.
>
> Your explanation is convincing for varname=VAR2 but now I would expect
> different results for varname=VAR2[@].
>
> Current actual results:
> $ VAR2=(aaa bbb)
> $ varname="VAR2[@]"
> $ echo "${VAR2@Q}"
> 'aaa'
> $ echo "${VAR2[@]@Q}"
> 'aaa' 'bbb'
> $ echo "${!varname@Q}"
>
> $ echo "${!varname[@]@Q}"
>
> $
>
> Expected results for last 2 commands:
>
> $ echo "${!varname@Q}"
> 'aaa' 'bbb'
This is correct output, and there's a bug here.
> $ echo "${!varname[@]@Q}"
> bash: ${VAR2[@][@]@Q}: bad substitution # This is example from
> direct usage of [@][@]
This is not; it should echo the same as the previous case, for the same
reason as I stated above (expand varname[@]; it expands to the same thing
as varname since varname is not an array variable; use the expansion to
VAR2[@]).
--
``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/
Back to gnu.bash.bug | Previous | Next | Find similar
Re: ${!variable@operator} does not work for variables without values; inconsistencies between present and absent [@] for @A and @a Chet Ramey <chet.ramey@case.edu> - 2020-02-21 09:37 -0500
csiph-web