Skip to content

TinkasAndStinkas.com

  • About
  • Contact Us

BASH: The octal problem

March 31, 2006 by tinkas

I was writing a whole pile of scripts which performed end of month tasks for this webserver, including stats archival, monthly backups, clean up bits and pieces. They all ran great until I hit the end of August and BANG...everything fell apart in a heap of "value too great for base (error token is "08")" Damn, said I, so off to find a way to fix it all.

I was writing a whole pile of scripts which performed end of month tasks for this webserver, including stats archival, monthly backups, clean up bits and pieces. They all ran great until I hit the end of August and BANG…everything fell apart in a heap of “value too great for base (error token is “08”)” Damn, said I, so off to find a way to fix it all.

The problem turned out to be Octal numbering, which can be solved by lifting whole chunks of somebody much smarters post:
from Payne’s Playhouse ยป bashing octal numbers into decimal

The problem is fixed in one of two ways. GNU date can be told not to zero pad the numbers by inserting a hyphen between the ‘%’ and ‘m’:
MTH=$((`date +%-m` – 1))
The bash shell can also be told the number is decimal by using the base#number notation as follows:
MTH=$((10#`date +%m` – 1))
For September this modifies the date output to be 10#09, which bash evaluates as a decimal instead of octal 9. This method can be applied more generally to anytime a script is returning zero padded values that should be interpreted as decimal numbers.

Post navigation

Previous Post:

Everybody meet Amy Joy

Next Post:

Important Information

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Mini Steer North
  • Time to get back on this horse
  • And the netball season begins
  • Happy 10th Birthday Big Girl
  • I really should restart this

Recent Comments

  • Dave on Important Information
  • Susan on Everybody meet Amy Joy
  • Darrel on Dancing the Night Away
  • Simon Heap on We are the champions.
  • Linda on Babies Update

Archives

  • September 2016
  • February 2016
  • May 2010
  • February 2010
  • September 2009
  • August 2009
  • July 2006
  • June 2006
  • April 2006
  • March 2006
  • February 2006
  • December 2005
  • November 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005

Categories

  • Family
  • Friends
  • Other Stuff
  • Photo Gallery
  • Uncategorized

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
© 2021 TinkasAndStinkas.com | WordPress Theme by Superb Themes