EN
Bash - detect operating system
5 points
In this short article, we would like to show how to check used operating system under Bash.
Quick solution:
xxxxxxxxxx
1
2
3
case "$OSTYPE" in
4
solaris*) echo "Solaris" ;;
5
darwin*) echo "OSX" ;;
6
linux*) echo "Linux" ;;
7
bsd*) echo "BSD" ;;
8
msys*) echo "Windows" ;;
9
cygwin*) echo "Windows" ;;
10
*) echo "Unknown operating system: $OSTYPE" ;;
11
esac
Example summary:
tested echo "$OSTYPE" result | System + Description |
---|---|
linux-gnu |
Debian |
msys |
Windows |
cygwin | Windows Bash from https://cygwin.com/install.html |
darwin19.0 |
OSX |