Fix/portability

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