My patches (many small things. See below)

+ Option to handle output (:silent, :error or :full)
+ Make temporary files more random because using $$
  is not enough to prevent duplication
+ Clean up spaces and use some Bash-specific features
+ Always return 0