Export relevant env variable
ShellCheck style and syntax fixes

Discovered using http://www.shellcheck.net/