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


Groups > gnu.bash.bug > #14934

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

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: Error on arithmetic evaluation of `~0`.
Date 2018-12-20 08:12 -0500
Message-ID <mailman.5994.1545312118.1284.bug-bash@gnu.org> (permalink)
References <CAFra36gW8Csu-84oRLV7QsR7PbiMYq6g7WnMktjfnrSdTys38g@mail.gmail.com>

Show all headers | View raw


On Wed, Dec 19, 2018 at 10:31:36PM -0500, Bize Ma wrote:
> 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 is not 0.

wooledg:~$ echo $(( ~0))
-1

The issue you're reporting appears to be present in arithmetic contexts
in general, not only arrays:

wooledg:~$ echo $((~0))
bash: /home/wooledg: syntax error: operand expected (error token is "/home/wooledg")

It appears that bash is performing tilde expansion when there's no
whitespace in front of the tilde, or bitwise negation if there is
whitespace.

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


Thread

Re: Error on arithmetic evaluation of `~0`. Greg Wooledge <wooledg@eeg.ccf.org> - 2018-12-20 08:12 -0500

csiph-web