bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ${!variable@operator} does not work for variables without values; i


From: Arfrever Frehtes Taifersar Arahesis
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 01:46:25 +0100

Eli Schwartz <eschwartz@archlinux.org> 2020-02-20 23:49 UTC:
> Your examples are all (still) broken.

This would affect only 10 examples from 120, so only 8.33 % of
examples, far from all examples.

> You cannot use ${!ref[@]}, you need the array subscript as part of the
> set value of "ref" and then indirectly refer to ref.
>
> $ declare -A VAR2=([foo]=bar [baz]="how interesting")
> $ args "${!VAR2[@]}"
> <foo> <baz>
> ...
> And, as predicted, if instead of using ${!ref[@]} you use
> ${!varname[@]}, you get meaningful information.

But I am not interested in any ${!varname[@]}, but instead in applying
@operator transformations.

>From `man bash`:
```
       ${parameter@operator}
              Parameter  transformation.   The  expansion is either a
transformation of the value of parameter or information about
parameter itself, de‐
              pending on the value of operator.  Each operator is a
single letter:

              Q      The expansion is a string that is the value of
parameter quoted in a format that can be reused as input.
              E      The expansion is a string that is the value of
parameter with backslash escape sequences expanded as with the $'...'
quoting  mecha‐
                     nism.
              P      The  expansion  is  a string that is the result
of expanding the value of parameter as if it were a prompt string (see
PROMPTING be‐
                     low).
              A      The expansion is a string in the form of an
assignment statement or declare command that, if evaluated, will
recreate parameter with
                     its attributes and value.
              a      The expansion is a string consisting of flag
values representing parameter's attributes.

              If parameter is @ or *, the operation is applied to each
positional parameter in turn, and the expansion is the resultant list.
If parame‐
              ter is an array variable subscripted with @ or *, the
operation is applied to each member of the array in turn, and the
expansion  is  the
              resultant list.
```

Is there any way for using ${!variable} combined with
${variable@operator} to get useful results for multi-elemental arrays?
If not, then I can still use `eval` :) .

$ ARRAY=(あ い う え お)
$ REF=ARRAY
$ eval "echo \"\${${REF}[@]@A}\""
declare -a ARRAY=([0]="あ" [1]="い" [2]="う" [3]="え" [4]="お")
$ eval "echo \"\${${REF}[@]@a}\""
a a a a a
$ echo "${ARRAY[@]@A}"
declare -a ARRAY=([0]="あ" [1]="い" [2]="う" [3]="え" [4]="お")
$ echo "${ARRAY[@]@a}"
a a a a a
$

Majority (3 of 4) of bugs reported by me in this thread are unaffected
by above discussion about ${!...} and are certainly still valid.

--
Arfrever Frehtes Taifersar Arahesis



reply via email to

[Prev in Thread] Current Thread [Next in Thread]