Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14942
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: Error on arithmetic evaluation of `~0`. |
| Date | 2018-12-22 12:00 -0500 |
| Organization | ITS, Case Western Reserve University |
| Message-ID | <mailman.6137.1545498030.1284.bug-bash@gnu.org> (permalink) |
| References | <CAFra36gW8Csu-84oRLV7QsR7PbiMYq6g7WnMktjfnrSdTys38g@mail.gmail.com> |
On 12/19/18 10:31 PM, Bize Ma wrote:
> This is the third time I am reporting this issue.
Not really, but let's go on.
>
> This fails:
>
> var=(hello); echo "${var[~0]}"
> syntax error: operand expected ...
Yes. The comment in the code says:
"Right now, the code
suppresses tilde expansion when expanding in a pure arithmetic
context, but allows it when expanding an array subscript. This is
for backwards compatibility, but I figure nobody's relying on it"
I suppose backwards compatibility here is less important at this point.
>
> While this works:
>
> var=(hello); echo "${var[ ~0]}"
> hello
Because negative array subscripts count backwards from the end of the
array.
> It is also interesting that this fails:
>
> var=hello; echo "${var[ ~0]}"
> bash: var: bad array subscript
>
> Isn't `var[0]` valid and equivalent to `var` ?
Yes, but ~0 (-1) is not the same as 0.
> This was "supposed" to be resolved in a dev version,
> but is still present on bash 5.
The other arithmetic contexts you reported (the "pure" arithmetic contexts
the comment above references) were changed; this was left for backwards
compatibility. Like I said above, it looks like it's time to deemphasize
that.
Chet
--
``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 | Unroll thread
Re: Error on arithmetic evaluation of `~0`. Chet Ramey <chet.ramey@case.edu> - 2018-12-22 12:00 -0500
csiph-web