Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15001

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

From konsolebox <konsolebox@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Error on arithmetic evaluation of `~0`.
Date 2018-12-29 20:09 +0800
Message-ID <mailman.6517.1546085718.1284.bug-bash@gnu.org> (permalink)
References <CAFra36gW8Csu-84oRLV7QsR7PbiMYq6g7WnMktjfnrSdTys38g@mail.gmail.com> <25e8adf0-96d5-1e38-faea-e7620ba3f846@case.edu> <CAFra36gzzbJLjqt9OYtJUuJara3KR2+ew-Gj3y2mA2L4X8CRyw@mail.gmail.com> <fc279c3d-35f8-1afa-e515-bfcf2f3bed44@case.edu> <CAFra36htTMBLVXARod9FX__5GY_PXhZ9BJB-Tp5fdiMdGHDx2A@mail.gmail.com>

Show all headers | View raw


On Sat, Dec 29, 2018, 1:44 PM Bize Ma <binaryzebra@gmail.com wrote:

> Chet Ramey (<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?).
>

That consistency would demand that simple variables be treated exactly as
array variables, but they aren't. The consistent part here is that they
convert dynamically when indexed, and 0 is the only synonymous index if the
variable would have been an array. A different index would demand two step
conversion. And if bash would ever allow those inidices like the positive
ones, it would only be for the sake of convenience, but that shouldn't be
taken strictly.

If you want consistency, stop treating non-array variables as array
variables and write explicit declarations or conversions. Natural indices
are fine, but special non-generic ones that are clearly just for arrays are
not.


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

Read the source code so you would undestand that arrays and non-arrays are
different.

>

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Error on arithmetic evaluation of `~0`. konsolebox <konsolebox@gmail.com> - 2018-12-29 20:09 +0800

csiph-web