Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14318 > unrolled thread
| Started by | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| First post | 2018-07-10 11:09 -0400 |
| Last post | 2018-07-10 11:09 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Number with sign is read as octal despite a leading 10# Chet Ramey <chet.ramey@case.edu> - 2018-07-10 11:09 -0400
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Date | 2018-07-10 11:09 -0400 |
| Subject | Re: Number with sign is read as octal despite a leading 10# |
| Message-ID | <mailman.3382.1531235361.1292.bug-bash@gnu.org> |
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.
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.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Back to top | Article view | gnu.bash.bug
csiph-web