Subject: Re: Arithmetic, octal and leading zeroes in sh
To: Stephen Borrill <email@example.com>
From: matthew sporleder <firstname.lastname@example.org>
Date: 10/13/2005 12:52:14
You should use expr in sh scripts to do arithmatic:
$>echo `expr 08 + 1`
$>echo `expr 09 + 1`
$>echo `expr 010 + 1`
$>expr `date +%M` + 08
To explain your example a little better.
This way, your shell scritps will work outside of over-featured bourne shel=
On 10/13/05, Stephen Borrill <email@example.com> wrote:
> On Thu, 13 Oct 2005, Todd Vierling wrote:
> >> I see from the 1.11 commit this is to recognise octal and hex, but mus=
> >> leading zero always indicate octal?
> > Yes; that's standard practice in Unix (and the C programming language).
> Sure, but I meant must it always do so in the shell? Doing so requires
> scripts to work around this if they want to use 'normal' :-) arithmetic
> on numbers that may be, for instance, input by the user or returned from
> date +%M
> > It is also required by the Open Group shell specification:
> That answers the question above.