Last active
May 16, 2023 04:06
-
-
Save lyndell/8c5ef8ff9eba2098717f to your computer and use it in GitHub Desktop.
test for the OS with the shell environment variable $OSTYPE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
# | |
# From: http://stackoverflow.com/questions/394230/detect-the-os-from-a-bash-script | |
PLATFORM=$(uname) | |
case "$PLATFORM" in | |
"Darwin") | |
# macOS | |
;; | |
"Linux") | |
# Linux distro, | |
;; | |
esac | |
case "$OSTYPE" in | |
solaris*) echo "SOLARIS" ;; | |
darwin*) echo "OSX" ;; | |
linux*) echo "LINUX" ;; | |
bsd*) echo "BSD" ;; | |
*) echo "unknown: $OSTYPE" ;; | |
esac | |
if [[ "$OSTYPE" == "linux-gnu" ]]; then | |
# ... | |
echo "linux-gnu" | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
# ... | |
echo "darwin" | |
elif [[ "$OSTYPE" == "cygwin" ]]; then | |
# ... | |
echo "cygwin" | |
elif [[ "$OSTYPE" == "win32" ]]; then | |
# ... | |
echo "win32" | |
elif [[ "$OSTYPE" == "freebsd" ]]; then | |
# ... | |
echo "freebsd" | |
else | |
# Unknown. | |
echo "Wow, that's a weird one.\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment