bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: value too great for base (error token is "0008")


From: Chris F.A. Johnson
Subject: Re: value too great for base (error token is "0008")
Date: Wed, 4 Nov 2009 10:29:49 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Wed, 4 Nov 2009, Eric Blake wrote:
> According to Greg Wooledge on 11/4/2009 6:23 AM:
> > On the other hand, removing a single leading zero is not difficult:
> > 
> >   month=$(date +%m) month=${month#0}   # Removing leading 0
> 
> Not portable.  Assigning the same variable twice in the same statement has
> different order of operations in some shells.  Use:
> 
> month=$(date +%m); month=${month#0}
> 
> instead.
> 
> >   next_month=$(( ($month == 12) ? 1 : $month+1 ))
> > 
> > Removing multiple leading zeroes, however, requires either a loop, or the
> > use of extended globs.
> 
> Not true.  You can do it via POSIX and without a loop by using an
> intermediate variable:
> 
> foo=00081
> bar=${foo%%[!0]*}
> foo=${foo#$bar}}

   Or even without an intermediate variable:

foo=${foo#${foo%%[!0]*}}

   (Though I prefer the variable for legibility.)

-- 
   Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]