bug-bash
[Top][All Lists]
Advanced

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

Re: Error on arithmetic evaluation of `~0`.


From: Chet Ramey
Subject: Re: Error on arithmetic evaluation of `~0`.
Date: Sat, 29 Dec 2018 10:46:18 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.3.3

On 12/28/18 11:26 PM, Bize Ma wrote:
> Chet Ramey (<chet.ramey@case.edu <mailto:chet.ramey@case.edu>>) wrote:
> 
>     On 12/23/18 12:01 PM, Bize Ma wrote:
> 
> {…}
> 
>     > Both command line above should have printed "hello".
> 
>     No. 0 is the only valid subscript for a non-array variable. The difference
>     between bash and other shells that implement this feature is that bash
>     warns about negative subscripts.
> 
> 
> If you say so: fine for me.
> 
> It still irks me a little that a `${var[-1]}` isn't the "last value"
> (sometimes!, consistency?).

The goal is not to make non-array variables look exactly like array
variables; the goal is to provide a little bit of syntactic sugar in
the rare case that it's useful. It's the analog to referencing an array
variable without using a subscript, which references element 0.

> I haven't seen that documented anywhere, though.

Which part? The fact that non-array variables can be referenced using
subscript 0?

-- 
``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/



reply via email to

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