This will break if the path contains - say - a space.
This is true for a number of lines in this file (any call to `dirname`, `basename` and `cd`).
Here that should probably have read `cd "`dirname \"$0\""`