Error messages to stderr, fixed missing $ in dirname, fixed bash style

Some fixes.