Fix shell tools for Linux

The shell scripts in the repo currently do not work at all for Linux systems. These changes allow the scripts to be run on Linux based systems, while still detecting whether the user is running OSX, and adjusts accordingly. The commits also include some general cleanup and fixing of existing code.

I split up the changes into several smaller commits, which both makes it clearer what each change does, and allows me to if needed "remove" any changes which are deemed "unrelated" to this pull request.

Tested and confirmed working on Ubuntu, but not any other Linux-based operating systems. As I don't have a MAC, I am unable to test if the shell scripts still work for OSX systems.