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

2018-08-12 Thread Isaac Marcos
Chet Ramey (mailto:chet.ra...@case.edu>>) wrote: > It doesn't matter. Unary plus and minus are operators, not part of integer constants. But you are confused, what is after the 10# is not an integer constant, it is an string. An string that is being parsed by bash C code and coerced into a sign o

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

2018-07-12 Thread Robert Elz
Date:Tue, 10 Jul 2018 18:46:32 -0400 From:Isaac Marcos Message-ID: | set -- 34 034 0034 +34 +034 +0034 -34 -034 -0034 ; | for i do printf '%6s' "$((10#$i))"; shift; done; echo You really ought be only using POSIX defined sh operators, from two

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

2018-07-10 Thread Chet Ramey
On 7/10/18 6:46 PM, Isaac Marcos wrote: > 2018-07-10 18:12 GMT-04:00 Eduardo Bustamante >: > > On Tue, Jul 10, 2018 at 1:57 PM, Isaac Marcos > mailto:isaacmarcos100...@gmail.com>> wrote: > > Chet Ramey (mailto:chet.ra...@case.edu>>) wrote: > [..] > >

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

2018-07-10 Thread Chet Ramey
On 7/10/18 4:57 PM, Isaac Marcos wrote: > Chet Ramey (mailto:chet.ra...@case.edu>>) wrote: > > On 7/10/18 2:48 PM, Isaac Marcos wrote: > >     That is not an integer constant. Integer constants don't begin > with `-'. > > > That makes negative numbers invalid. You need to look at th

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

2018-07-10 Thread Isaac Marcos
According to Chet, the definition > is the same as the ISO C standard. I'm not sure if there's a public > version of the ISO C standard document, but > http://c0x.coding-guidelines.com/6.4.4.1.html seems to be good enough. > The definition of an "integer constant" in that document does not > includ

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

2018-07-10 Thread Isaac Marcos
2018-07-10 18:12 GMT-04:00 Eduardo Bustamante : > On Tue, Jul 10, 2018 at 1:57 PM, Isaac Marcos > wrote: > > Chet Ramey () wrote: > [..] > > This is not a serious argument. > [...] > > I don't care. All other shells do this correctly. It makes you the only > one > > wrong. > > > > This is not a s

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

2018-07-10 Thread Eduardo Bustamante
On Tue, Jul 10, 2018 at 1:57 PM, Isaac Marcos wrote: > Chet Ramey () wrote: [..] > This is not a serious argument. [...] > I don't care. All other shells do this correctly. It makes you the only one > wrong. > > This is not a serious discussion. Can you keep the discussion civil? I don't get why

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

2018-07-10 Thread Isaac Marcos
Chet Ramey () wrote: > On 7/10/18 2:48 PM, Isaac Marcos wrote: > > That is not an integer constant. Integer constants don't begin with > `-'. > That makes negative numbers invalid. This is not a serious argument. Because of the difference between an operator and a constant. Unary plus > and

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

2018-07-10 Thread Ilkka Virta
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'

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

2018-07-10 Thread Pierre Gaston
On Tue, Jul 10, 2018 at 1:44 PM, 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 leadi

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

2018-07-10 Thread Chet Ramey
On 7/10/18 11:04 AM, Greg Wooledge wrote: > On Tue, Jul 10, 2018 at 11:00:36AM -0400, Chet Ramey wrote: >> On 7/9/18 9:24 PM, Isaac Marcos wrote: >> >>> Bash Version: 4.4 >>> Patch Level: 12 >>> Release Status: release >>> >>> Description: >>> A value inside an arithmetic expansion is processed as

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

2018-07-10 Thread Chet Ramey
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, whi

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

2018-07-10 Thread Greg Wooledge
On Tue, Jul 10, 2018 at 11:00:36AM -0400, Chet Ramey wrote: > On 7/9/18 9:24 PM, Isaac Marcos wrote: > > > Bash Version: 4.4 > > Patch Level: 12 > > Release Status: release > > > > Description: > > A value inside an arithmetic expansion is processed as octal despite using > > a 10# preffix. > >

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

2018-07-10 Thread Chet Ramey
On 7/9/18 9:24 PM, Isaac Marcos wrote: > Bash Version: 4.4 > Patch Level: 12 > Release Status: release > > Description: > A value inside an arithmetic expansion is processed as octal despite using > a 10# preffix. An integer constant cannot contain a `+'. > > Repeat-By: > $ echo $((10#

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

2018-07-10 Thread Ilkka Virta
For what it's worth, ksh and zsh seem to interpret 10#-0159 as negative one-hundred and fifty-nine: $ ksh -c 'for a do a="10#$a"; printf "%s " $((a + 1)); done; echo' \ sh +159 +0159 -159 -0159 160 160 -158 -158 $ zsh -c 'for a do a="10#$a"; printf "%s " $((a + 1)); done; echo' \ sh +159 +01

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

2018-07-10 Thread Ilkka Virta
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)

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

2018-07-09 Thread Clint Hepner
The + is a unary operator, not part of the literal. Write $((+10#0034)) instead. -- Clint On Jul 9, 2018, 9:24 PM -0400, Isaac Marcos , wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: linux-gnu > Compiler: gcc > Compilation CFLAGS: -DPROGRAM='b