Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Greg Wooledge 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: References: 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 To: Bize Ma Envelope-to: bug-bash@gnu.org Mail-Followup-To: Bize Ma , bug-bash Content-Disposition: inline In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14934 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.