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


Groups > gnu.bash.bug > #14321

Re: Number with sign is read as octal despite a leading 10#

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Ilkka Virta <itvirta@iki.fi>
Newsgroups gnu.bash.bug
Subject Re: Number with sign is read as octal despite a leading 10#
Date Tue, 10 Jul 2018 21:41:56 +0300
Lines 48
Approved bug-bash@gnu.org
Message-ID <mailman.3391.1531248126.1292.bug-bash@gnu.org> (permalink)
References <CA+n9pTy7vSPUA0j-bDF9_eWF0XysePRDAFckgvvHX8haSWv7KQ@mail.gmail.com> <c8ae5df2-b6b3-438f-bd99-4618f6b2d3c0@Spark> <71850c03-54d3-6a7e-1d29-136950d9e139@iki.fi> <a0b100e7-3e14-e56e-8ffb-fcaeca587bf1@case.edu>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1531248127 8841 208.118.235.17 (10 Jul 2018 18:42:07 GMT)
X-Complaints-To action@cs.stanford.edu
Cc Clint Hepner <clint.hepner@gmail.com>, bug-bash@gnu.org, bash@packages.debian.org, Isaac Marcos <isaacmarcos100010@gmail.com>
To chet.ramey@case.edu
Envelope-to bug-bash@gnu.org
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.0
In-Reply-To <a0b100e7-3e14-e56e-8ffb-fcaeca587bf1@case.edu>
Content-Language en-US
X-SASI-RCODE 200
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; h=subject:to:references:cc:from:message-id:date:mime-version:in-reply-to:content-type:content-transfer-encoding; s=smtp; bh=bMFOXxHe5cwBABVjRMNLA4+qgQ6+qbOhr4muO3J2eGE=; b=mJ6eld2YwPv9H4kj8fcSoBZzPGpV3VO8QEl/vcyIHGhlO419qFdYvFaHIFk7JRSqjMu/lezCWE3B+MFW9AeFxlrOMvZ+TmwB9+YV5vajYnxmhL+XXrwGRENwx4Th52xzzskYq65IsgU57w7TVds5TiD2EU1d6EsCATPQN0oAaQW4BWzW6nbOLPKJWqsvkZZw5cuBifZDRjPFPZsPlIBmcBBSvMNDiWLKmuMAfvKeSoYd0mFkjU9p9USSx9DZiQOQLvSjaAbCaJ7q3u25ItFCq/ul2IEYOigq3fSvP3S3darWPgvDR0t5yEq8dpUMuO8RLMmnVC5pbQT1IMHB9oaQhg==
X-detected-operating-system by eggs.gnu.org: FreeBSD 8.x [fuzzy]
X-Received-From 157.24.2.104
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:14321

Show key headers only | View raw


On 10.7. 18:09, Chet Ramey wrote:
> On 7/10/18 6:44 AM, Ilkka Virta wrote:
>> I think the problematic case here is when the number comes as input from
>> some program, which might or might not print a leading sign or leading
>> zeroes, but when we know that the number is, in any case, decimal.
>>
>> E.g. 'date' prints leading zeroes, which is easy enough to handle:
>>
>> hour=$(date +%H)
>>
>> hour=${hour#0}         # remove one leading zero, or
>> hour="10#$hour"        # make it base-10
>>
>> The latter works even with more than one leading zero, but neither works
>> with a sign. So, handling numbers like '-00159' gets a bit annoying:
> 
> That is not an integer constant. Integer constants don't begin with `-'.
> Bash uses the same definition for constants as the C standard, with the
> addition of the `base#value' syntax.

At least from my point of view this isn't necessarily a bug, more like a 
feature request. The behaviour matches the description you just wrote, 
and also the documentation. That doesn't mean it's the only possible 
behaviour.

Changing the parsing here could be useful, and would improve 
compatibility with ksh and zsh. I don't think there's any alternative 
sensible meaning for  10#-0123  anyway, but I might be mistaken.

> Since the `10#' notation is sufficient to deal with leading zeroes if you
> want to force decimal, you only have to remove a leading unary plus or
> minus.

Which I thought I just did, and Pierre provided a better way to do it 
(thanks).

Not having to splice the sign around would make this somewhat easier 
though, but YMMV.

-- 
Ilkka Virta / itvirta@iki.fi

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


Thread

Re: Number with sign is read as octal despite a leading 10# Ilkka Virta <itvirta@iki.fi> - 2018-07-10 21:41 +0300

csiph-web