Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14942 > unrolled thread
| Started by | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| First post | 2018-12-22 12:00 -0500 |
| Last post | 2018-12-22 12:00 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Error on arithmetic evaluation of `~0`. Chet Ramey <chet.ramey@case.edu> - 2018-12-22 12:00 -0500
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Date | 2018-12-22 12:00 -0500 |
| Subject | Re: Error on arithmetic evaluation of `~0`. |
| Message-ID | <mailman.6137.1545498030.1284.bug-bash@gnu.org> |
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 top | Article view | gnu.bash.bug
csiph-web