Fix/portability

extending @drkibitz's branch (#363) with a bunch more portability fixes.

Tests now pass with dash as `/bin/sh` on Ubuntu 13.10.

Now back to FreeBSD :)