[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: doing simple math in bash :: prb with leading zero
From: |
Chris F.A. Johnson |
Subject: |
Re: doing simple math in bash :: prb with leading zero |
Date: |
Tue, 1 Sep 2009 18:05:45 -0400 (EDT) |
User-agent: |
Alpine 2.00 (LMD 1167 2008-08-23) |
On Tue, 1 Sep 2009, Linda Walsh wrote:
> ken wrote:
> > Doing very simple math in bash fails if a number begins with a zero (0).
> > The short script below illustrates the problem:
> ---
> Normally, a leading 0 begins an octal constant (I have been bitten
> by this in the past as well...).
>
> Where are you getting the value 'lastmo' from?
>
> If from 'something like date +"%m"', maybe you could strip off the leading
> zero? I.e.:
>
> lastmo=$(echo "$lastmo"|sed -r 's/0+([0-9])/\1/')
Surely you mean:
lastmo=${lastmo#0}
--
Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)