Subject: Re: Arithmetic, octal and leading zeroes in sh
To: Stephen Borrill <netbsd@precedence.co.uk>
From: matthew sporleder <msporleder@gmail.com>
List: netbsd-users
Date: 10/13/2005 12:52:14
You should use expr in sh scripts to do arithmatic:
$>echo `expr 08 + 1`
9
$>echo `expr 09 + 1`
10
$>echo `expr 010 + 1`
11

or..
$>date +%M
51
$>expr `date +%M` + 08
59

To explain your example a little better.

This way, your shell scritps will work outside of over-featured bourne shel=
ls.

On 10/13/05, Stephen Borrill <netbsd@precedence.co.uk> 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=
t a
> >> 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.
>
> --
> Stephen
>
>