How to find the operating system using bash script? I found this answer: Detect the OS from a Bash script. It is not clear it would work on Mac OS X.
I would like to find it on Mac OS X vs different linux OS's.
How to find the operating system using bash script? I found this answer: Detect the OS from a Bash script. It is not clear it would work on Mac OS X.
I would like to find it on Mac OS X vs different linux OS's.
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 options
function 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