Monday, February 28, 2011

bash treats numbers with leading 0 as octal

In a bash script, the number of the current week is used to select a different tape every week (rotation of 4 tapes) :


WEEK=`date +%W` # Week number (01..52)
TAPE=$((WEEK % 4))

This worked fine so far, but this weekend (it's the 8th weekend of the year) there was an error :

value too great for base (error token is "08")

After some digging, I found that bash treats numbers with a leading 0 as octal. But value 8 (and 9) don't exist in octal, so that's why it throws an error. With smaller numbers (01-07), there is no problem, because they are valid octal numbers, and for bigger numbers (10-...), the number is treated in decimal format, because there is no leading 0 anymore.

This problem can be fixed in two ways :

1) strip leading 0 from value

In bash you can do this with this command :

WEEK=${WEEK#0} # strip leading 0

This only removes a leading zero, a zero that is not leading will not be removed.

2) convert value to decimal

TAPE=$((10#$WEEK % 4)) # convert $WEEK to base-10 with '10#'

Note that you have to add the $ in front of the variable WEEK, to treat it is a variable, in order for the conversion (with 10#) to work.

Sunday, February 13, 2011


It's been great again. Over 5000 Open Source developers and enthousiasts meeting to share more than 200 hours of knowledge over the course of a weekend at FOSDEM 2011, held at campus Solbosch of ULB in Brussels, Belgium.
Last year I went there for the first time, for just one day, and I liked it so much I immediately decided to go back this year, but for the whole two days.

So there I was, on Saturday afternoon, after taking two trains, a metro and a bus, entering the ULB campus where FOSDEM is held, seeing the signs pointing to all different buildings and rooms where talks were held, the catering trucks, and a busy bunch of enthousiastic people.

I headed for the MySQL & Friends devroom, where I met some of the people of the phpMyAdmin team, which I joined last year. I hadn't met them before, so this was a nice opportunity.
These are some of the talks I attended on Saturday :

After this, we had a phpMyAdmin team dinner and afterwards I introduced them to  some fine Belgian beers.

Sunday was a bit chaotic, I hadn't planned to see that much talks, one of the talks I planned to attend was canceled, and I missed another one, because I left early to catch the canceled one (but I didn't know it at that time), but I still went to some :

After the last talk, it was time to go home. A special FOSDEM bus brought us back to the railway station, were I had some dinner before I headed home.
It was a nice weekend, with a nice Open atmosphere, again perfectly organized by and for the community.  In case you missed it, this was FOSDEM 2011 (a video artists impression).

I'm looking forward to next edition already!

Monday, February 07, 2011

Debian 6 (Squeeze) is released.

A few days ago, Debian 6.0, codename Squeeze, was released after a 2 year development period.

Of course this new release contains a lot of new stuff : lots of new and upgraded packages, faster booting because processes are started in parallel (if dependencies allow it), integration of grub2, volatile repository is replaced by squeeze-updates, ...

Because I want to use Tomcat 6 on a production server, I wanted to try the upgrade on a testbox. Everything went quite smoothly. All steps for upgrading from Debian 5.0 (Lenny) are clearly explained in the release notes (Chapter 4). The only thing that went wrong, in my case was the update of mysql-server. For some reason it was uninstalled, but the replacement package for the new version 5.1 was not installed.

After the upgrade process, I rebooted and I noticed grub 0.97 (now called grub-legacy) was still used, but it transfered the bootprocess to grub2. This worked like a charm, so then I ran  (as root) :

# upgrade-from-grub-legacy

to install grub2 in the MBR and boot from it. Rebooting went perfectly afterwards.

So far I'm quite pleased with squeeze and the upgrade process. I'll do the upgrade with my other boxes in the next few days.