Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14320
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Pierre Gaston <pierre.gaston@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Number with sign is read as octal despite a leading 10# |
| Date | Tue, 10 Jul 2018 19:16:33 +0300 |
| Lines | 34 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.3386.1531239420.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> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| X-Trace | usenet.stanford.edu 1531239420 3578 208.118.235.17 (10 Jul 2018 16:17:00 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | Clint Hepner <clint.hepner@gmail.com>, "bug-bash@gnu.org" <bug-bash@gnu.org>, bash@packages.debian.org, Isaac Marcos <isaacmarcos100010@gmail.com> |
| To | Ilkka Virta <itvirta@iki.fi> |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=pAipob5+SwBStZd0xBLNHKv0QBDwhj7szVH3VykkgaU=; b=QOpZ12/uM3tEdJID/3htJ5hrlY0fXtct7qe2HB0jWsyCsyvQHKhaDbxwIdWgR3uKou hPgq0g1efwzrqpqtQY7um+3lwMY1lj2P1gV8LO1kiPgmNqK/tg9NLywKyf03J/p1Aidl ydnlBKEz6i/c64wPTXfhImkevFRQ69G05M6HesbKb8fvxs6ic8wmpOj6lPB/iEaY8odG FWElfIJatU9KZ9FFMHF74Ew9gvJoql/J1kzY2TkT9+Lr1wfl+hl1dTFwVHrZ+w967Hmg oI3d6231Shmf/U31843EpIa78+ZklAuKjFsZjRLNUNMatB8xpJGTrB7II6VJYtgK6vw4 Dayg== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=pAipob5+SwBStZd0xBLNHKv0QBDwhj7szVH3VykkgaU=; b=GWO36RjiCPc+kyckgKAR3f5RCoojYEk7ITMuPgIB3kHOPbNpI1rqoZTYX4bUXQYNs/ fPtBttZHAuHvkyHBHPJ5mNiolj7CyQNaZComA9tc0+AOMqe4gy/m9c2kFMowRw4B4eCw ANZ60oHPgyWMEn+Wtg1ewXb+RWDaN/fCdv4H+paDaOLPtBEf9lrLTL4oZ+/bYfGTZWcg OctjokTOVkWejqb2bh4yw7g0eqQUim8yZX1JPxJsVwRZ0JcIrz9O1eu3AlpKhXFQXWcy QOgYTgIB10GKUM4x7c1YtosLoyrQZjLjnyp8nvN3J2mvAzLDX+nvUG+KidkIvSEH1nds 3rJA== |
| X-Gm-Message-State | APt69E3hl4BaZ4nudFh/Xiys+AppFrUiD5Wj3KheqRFjZbzWeUSFd/z/ Un3lbagCKssYMwZ0CQ+b/lgmbRJkc2Y7blAuB2Q= |
| X-Google-Smtp-Source | AAOMgpcYzJ0X9QnNLF5iv0JIVEEUP9Lxd/5JAwldCV1xFtQc3wpqNeJj0/TIXTjrcRj1FrV+f6K/sZbzHpREUJ9hMbE= |
| X-Received | by 2002:a50:adaa:: with SMTP id a39-v6mr27872701edd.194.1531239414741; Tue, 10 Jul 2018 09:16:54 -0700 (PDT) |
| In-Reply-To | <71850c03-54d3-6a7e-1d29-136950d9e139@iki.fi> |
| X-detected-operating-system | by eggs.gnu.org: Genre and OS details not recognized. |
| X-Received-From | 2a00:1450:4864:20::52a |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.21 |
| 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:14320 |
Show key headers only | View raw
On Tue, Jul 10, 2018 at 1:44 PM, Ilkka Virta <itvirta@iki.fi> 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:
>
> $ num='-00159'
> $ num="${num:0:1}10#${num:1}"; echo $(( num + 1 ))
> -158
>
> And that's without checking that the sign was there in the first place.
>
>
> Something like that will probably not be too common, but an easier way to
> force any number to be interpreted in base-10 (regardless of leading
> zeroes) could be useful. If there is a way, I'd be happy to hear.
It's not too complicated to separate the sign from the number eg:
for num in 159 000159 +000159 -000159;do
echo $((${num%%[!+-]*}10#${num#[-+]}))
done
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Number with sign is read as octal despite a leading 10# Pierre Gaston <pierre.gaston@gmail.com> - 2018-07-10 19:16 +0300
csiph-web