Argh!

August 19th, 2006  |  Published in etc

caladan:~ mph$ man bash

 [...]

Constants with a leading 0 are interpreted as octal numbers.  A leading 

0x  or  0X  denotes  hexadecimal. 

That’s been messing with me all week in re: a shell script I wrote to generate the date as a quarter. The output from:

 let dat="((`date +%m`-1)/3)+1" 

Means that “dat” comes out as “0something,” because strftime doesn’t seem to allow for “month with no leading 0,” just %m’s “month with leading 0.” So bash reads dat as an octal value and ralfs when I try to do something more with the number because there’s no such thing as “08” in octal. It took, for those of you who like to read about this sort of thing, three months for this to manifest in the script generating the quarter, because, you know, 01 through 07 do exist.

Anyhow, looks like DateTime has pretty much what I need to do this with a simple $qtr = $dt->quarter.

I wouldn’t have to be embarrassed by this sort of kludgery if I kept it to myself, I guess.

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.