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


Groups > gnu.bash.bug > #14934 > unrolled thread

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

Started byGreg Wooledge <wooledg@eeg.ccf.org>
First post2018-12-20 08:12 -0500
Last post2018-12-20 08:12 -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.


Contents

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

#14934 — Re: Error on arithmetic evaluation of `~0`.

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2018-12-20 08:12 -0500
SubjectRe: Error on arithmetic evaluation of `~0`.
Message-ID<mailman.5994.1545312118.1284.bug-bash@gnu.org>
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.

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web