Languages
[Edit]
EN

Bash - detect operating system

5 points
Created by:
Wade
472

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

Quick solution:

#!/bin/bash

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

 

See also

  1. Bash - detect machine architecture (x86/x64) 
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - detect operating system
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