Get current operating system with a Bash script

## FIND CURRENT OS
OS="Unknown"
if [[ "$OSTYPE" == "linux-gnu" ]];then
    OS="Linux"
elif [[ "$OSTYPE" == "darwin"* ]];then
    OS="MacOS"
elif [[ "$OSTYPE" == "cygwin" ]];then
    # POSIX compatibility layer and Linux environment emulation for Windows
    OS="cygwin"
elif [[ "$OSTYPE" == "msys" ]];then
    # Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
    OS="msys"
elif [[ "$OSTYPE" == "win32" ]];then
    OS="Win32"
elif [[ "$OSTYPE" == "freebsd"* ]];then
    OS="FreeBSD"
fi
echo "Operating System: $OS"
Code language: Bash (bash)

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.