Improve output handling of shell script.