Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On 09/15/11 23:24, Abel Abraham Camarillo Ojeda wrote: On Thu, Sep 15, 2011 at 4:19 PM, Pascal Stumpfpascal.stu...@cubes.de wrote: On Thu, Sep 15, 2011 at 12:06:14PM +, Thorsten Glaser wrote: Abel Abraham Camarillo Ojedaacamariat verlet.org writes: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) month=10#$(date +%m) Is that a mkshism? The easiest solution here is: typeset -Z2 month Yep, I did that in some scripts, just don't know how portable it is... While the OT was not how to handle 0number as a decimal number, I am stunned that noone has suggested ${month#0} or ${month##+(0)} yet. The latter may possibly be less portable though. /Alexander
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
Abel Abraham Camarillo Ojeda acamari at verlet.org writes: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) month=10#$(date +%m) bye, //mirabilos
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
* Thorsten Glaser t...@mirbsd.de [2011-09-15 14:15]: Abel Abraham Camarillo Ojeda acamari at verlet.org writes: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) month=10#$(date +%m) awesome. trying to be clever is always so awesome, and almost always leads to problems. now, your code is awesome to produce something that looks like a military aircraft registration. it is entirely useless otherwise. -- Henning Brauer, h...@bsws.de, henn...@openbsd.org BS Web Services, http://bsws.de, Full-Service ISP Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed Henning Brauer Consulting, http://henningbrauer.com/
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Thu, Sep 15, 2011 at 12:06:14PM +, Thorsten Glaser wrote: Abel Abraham Camarillo Ojeda acamari at verlet.org writes: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) month=10#$(date +%m) Is that a mkshism? The easiest solution here is: typeset -Z2 month
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Thu, Sep 15, 2011 at 4:19 PM, Pascal Stumpf pascal.stu...@cubes.de wrote: On Thu, Sep 15, 2011 at 12:06:14PM +, Thorsten Glaser wrote: Abel Abraham Camarillo Ojeda acamari at verlet.org writes: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) month=10#$(date +%m) Is that a mkshism? The easiest solution here is: typeset -Z2 month Yep, I did that in some scripts, just don't know how portable it is...
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Thu, Sep 15, 2011 at 04:24:37PM -0500, Abel Abraham Camarillo Ojeda wrote: Yep, I did that in some scripts, just don't know how portable it is... I haven't come across a single ksh that doesn't support that. Even the old ksh88 on AIX 4.3.3 at my university has it.
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Thu, Sep 15, 2011 at 4:58 PM, Thorsten Glaser t...@mirbsd.de wrote: Abel Abraham Camarillo Ojeda dixit: On Thu, Sep 15, 2011 at 4:19 PM, Pascal Stumpf pascal.stu...@cubes.de wrote: month=10#$(date +%m) Is that a mkshism? No, that's proper Korn shell. The easiest solution here is: typeset -Z2 month That can break as soon as month is made an integer someplace down. Padding is meant for output, not input. Yep, I did that in some scripts, just don't know how portable it is... tg@stinky:~ $ /bin/ksh -c 'i=10#08; print $((i)) $(uname -a)' 8 SunOS stinky 5.8 Generic_117350-61 sun4u sparc SUNW,Sun-Fire-V210 Solaris So, portable across all Korn shells. bye, //mirabilos -- FWIW, I'm quite impressed with mksh interactively. I thought it was much *much* more bare bones. But it turns out it beats the living hell out of ksh93 in that respect. I'd even consider it for my daily use if I hadn't wasted half my life on my zsh setup. :-) -- Frank Terbeck in #!/bin/mksh I meant portable among other shells, or bourne shell...
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
Abel Abraham Camarillo Ojeda dixit: I meant portable among other shells, or bourne shell... They donbt have $((b)) either, sob bye, //mirabilos -- Yay for having to rewrite other people's Bash scripts because bash suddenly stopped supporting the bash extensions they make use of -- Tonnerre Lombard in #nosec
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Thu, Sep 15, 2011 at 09:58:13PM +, Thorsten Glaser wrote: typeset -Z2 month That can break as soon as month is made an integer someplace down. And that's very likely to happen ... Padding is meant for output, not input. You don't know if $month is input or output. tg@stinky:~ $ /bin/ksh -c 'i=10#08; print $((i)) $(uname -a)' 8 SunOS stinky 5.8 Generic_117350-61 sun4u sparc SUNW,Sun-Fire-V210 Solaris So, portable across all Korn shells. Based on the invalid assumption that i is always evaluated inside an arithmetical expression.
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
Abel Abraham Camarillo Ojeda dixit: On Thu, Sep 15, 2011 at 4:19 PM, Pascal Stumpf pascal.stu...@cubes.de wrote: month=10#$(date +%m) Is that a mkshism? No, that's proper Korn shell. The easiest solution here is: typeset -Z2 month That can break as soon as month is made an integer someplace down. Padding is meant for output, not input. Yep, I did that in some scripts, just don't know how portable it is... tg@stinky:~ $ /bin/ksh -c 'i=10#08; print $((i)) $(uname -a)' 8 SunOS stinky 5.8 Generic_117350-61 sun4u sparc SUNW,Sun-Fire-V210 Solaris So, portable across all Korn shells. bye, //mirabilos -- FWIW, I'm quite impressed with mksh interactively. I thought it was much *much* more bare bones. But it turns out it beats the living hell out of ksh93 in that respect. I'd even consider it for my daily use if I hadn't wasted half my life on my zsh setup. :-) -- Frank Terbeck in #!/bin/mksh
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Thu, Sep 15, 2011 at 5:46 PM, Thorsten Glaser t...@mirbsd.de wrote: Abel Abraham Camarillo Ojeda dixit: I meant portable among other shells, or bourne shell... They donbt have $((b)) either, sob bye, //mirabilos -- Yay for having to rewrite other people's Bash scripts because bash suddenly stopped supporting the bash extensions they make use of B B B B -- Tonnerre Lombard in #nosec I was talking about portability of typeset -Z2...
ksh: bad number (with leading zeroes) should not work for 0 - 7
Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) Suddenly started crashing on august... there seems to be a bug identifying not-numbers (numbers with leading zeroes) before '08' (eigth), how to reproduce: $ for i in 0{0,1,2,3,4,5,6,7,8,9}; do a=$i; a=$((a-1)); echo $a; done -1 0 1 2 3 4 5 6 ksh: 08: bad number `08' $ Thanks.
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On 09/12/2011 05:45 PM, Abel Abraham Camarillo Ojeda wrote: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) Suddenly started crashing on august... there seems to be a bug identifying not-numbers (numbers with leading zeroes) before '08' (eigth), how to reproduce: $ for i in 0{0,1,2,3,4,5,6,7,8,9}; do a=$i; a=$((a-1)); echo $a; done -1 0 1 2 3 4 5 6 ksh: 08: bad number `08' $ Seems like it's being interpreted as an octal number because of the leading zero. ksh93 on Linux does not interpret this as octal and runs the snippet fine. bash on linux does interpret it as octal and gives a similar error. /bin/ksh on OpenBSD 4.5 gives the same error so it is not a recent behavior change in OpenBSD. - Aner
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
* Abel Abraham Camarillo Ojeda acam...@verlet.org [110913 01:46]: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) Suddenly started crashing on august... there seems to be a bug identifying not-numbers (numbers with leading zeroes) before '08' (eigth), how to reproduce: Quoting ksh(1): Additionally, integers may be prefixed with `0X' or `0x' (specifying base 16) or `0' (base 8) in all forms of arithmetic expressions, except as numeric arguments to the test command. ksh: 08: bad number `08' 08 doesn't exist in base 8 -- Alexander Polakov | plhk.ru
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Mon, Sep 12, 2011 at 04:45:28PM -0500, Abel Abraham Camarillo Ojeda wrote: Some of our shell scripts that work with dates and do something like: month=`date +%m` something month=$((month-1)) Suddenly started crashing on august... there seems to be a bug identifying not-numbers (numbers with leading zeroes) before '08' (eigth), how to reproduce: $ for i in 0{0,1,2,3,4,5,6,7,8,9}; do a=$i; a=$((a-1)); echo $a; done -1 0 1 2 3 4 5 6 ksh: 08: bad number `08' The string 08 can not be converted into a number for doing calculations. The 0 prefix signifies an octal number and 08 is not valid in the octal system. Bash will also tell you that this can not be done. Fix your script, add the leading zero after you're done with the calculation. $ Thanks.
Re: ksh: bad number (with leading zeroes) should not work for 0 - 7
On Mon, Sep 12, 2011 at 5:08 PM, Tobias Ulmer tobi...@tmux.org wrote: Fix your script, add the leading zero after you're done with the calculation. I'm already doing that, just wasn't sure if it was a bug... Thanks.