Fix error message redirection to stdout.
Use bash idioms instead of temp files.

This fixes temp file portability issues on OS X.