Shell Script to find the Operating System of the machine
For Linux you can type in the following bash command:
$ cat /etc/*-release
For Mac OS X you can try one of these commands:
$ sw_vers -productVersion $ system_profiler SPSoftwareDataType
Derived from other answers, this worked for me:
CURRENT_OS="OSX" #CENTOS, UBUNUTU are other valid optionsfunction findCurrentOSType(){ echo "Finding the current os type" echo osType=$(uname) case "$osType" in "Darwin") { echo "Running on Mac OSX." CURRENT_OS="OSX" } ;; "Linux") { # If available, use LSB to identify distribution if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then DISTRO=$(gawk -F= '/^NAME/{print $2}' /etc/os-release) else DISTRO=$(ls -d /etc/[A-Za-z]*[_-][rv]e[lr]* | grep -v "lsb" | cut -d'/' -f3 | cut -d'-' -f1 | cut -d'_' -f1) fi CURRENT_OS=$(echo $DISTRO | tr 'a-z' 'A-Z') } ;; *) { echo "Unsupported OS, exiting" exit } ;; esac}
use uname
$(uname -s)
this will give you the os name (Darwin = OSX)
$(uname -v)
will give you the os version
see uname manual here