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


Groups > gnu.bash.bug > #14934

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

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: Error on arithmetic evaluation of `~0`.
Date Thu, 20 Dec 2018 08:12:58 -0500
Lines 23
Approved bug-bash@gnu.org
Message-ID <mailman.5994.1545312118.1284.bug-bash@gnu.org> (permalink)
References <CAFra36gW8Csu-84oRLV7QsR7PbiMYq6g7WnMktjfnrSdTys38g@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1545312118 6218 208.118.235.17 (20 Dec 2018 13:21:58 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash <bug-bash@gnu.org>
To Bize Ma <binaryzebra@gmail.com>
Envelope-to bug-bash@gnu.org
Mail-Followup-To Bize Ma <binaryzebra@gmail.com>, bug-bash <bug-bash@gnu.org>
Content-Disposition inline
In-Reply-To <CAFra36gW8Csu-84oRLV7QsR7PbiMYq6g7WnMktjfnrSdTys38g@mail.gmail.com>
User-Agent NeoMutt/20170113 (1.7.2)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 139.137.100.1
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14934

Show key headers only | 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