Shell improvements

Apart from a extraneous space removal, this replaces the call to the external `basename` binary with a shell function.