Languages
[Edit]
EN

Bash - detect operating system

5 points
Created by:
JustMike
28860

In this short article, we would like to show how to check used operating system under Bash.

Quick solution:

case "$OSTYPE" in
    solaris*) echo "Solaris" ;;
    darwin*)  echo "OSX" ;; 
    linux*)   echo "Linux" ;;
    bsd*)     echo "BSD" ;;
    msys*)    echo "Windows" ;;
    cygwin*)  echo "Windows" ;;
    *)        echo "Unknown operating system: $OSTYPE" ;;
esac

Example summary:

tested echo "$OSTYPE" resultSystem + Description
linux-gnu

Debian
Tested on version: 10.4

msys

Windows
Bash from https://gitforwindows.org

cygwinWindows
Bash from https://cygwin.com/install.html
darwin19.0

OSX
Tested on macOS Catalina, version: 10.15.3

Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join