Multi-platform shell scripts

While Linux and MacOS share a lot of similar terminal commands, some things remain different. Package management, for example. On Ubuntu, you commonly use APT, on MacOS, many use Brew. When you're writing a shell script that needs to run on both platforms, this poses a problem.

I recently had to write a "multi-platform" shell script and used this little code fragment:


system_type=$(uname -s)

if [ "$system_type" = "Linux" ]; then
  sudo apt-get -y install vim
elif [ "$system_type" = "Darwin" ]; then
  brew install vim
  echo "Panic!"  

Simple and effective. For anyone running into the same problem, here you go!