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:
#!/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" result | System + Description |
---|---|
linux-gnu |
Debian |
msys |
Windows |
cygwin | Windows Bash from https://cygwin.com/install.html |
darwin19.0 |
OSX |