[Top][All Lists]

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

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

From: Greg Wooledge
Subject: Re: Error on arithmetic evaluation of `~0`.
Date: Thu, 20 Dec 2018 08:12:58 -0500
User-agent: NeoMutt/20170113 (1.7.2)

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))

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 

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

reply via email to

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