Last active
January 31, 2019 18:19
-
-
Save marcusandre/4b88c2428220ea255b83 to your computer and use it in GitHub Desktop.
Get operating system as string identifier from $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/sh | |
# | |
# get os type | |
# | |
get_os() { | |
if [ -z $OSTYPE ]; then | |
OSTYPE=$(uname | tr '[:upper:]' '[:lower:]') | |
fi | |
case $OSTYPE in | |
freebsd*) echo "freebsd" ;; | |
netbsd*) echo "netbsd" ;; | |
openbsd*) echo "openbsd" ;; | |
darwin*) echo "mac" ;; | |
linux*) echo "linux" ;; | |
cygwin*) echo "cygwin" ;; | |
*) echo "unknown"; exit 1 ;; | |
esac | |
} |
edit: add bsd
types.
This will fail when OSTYPE
is set to something that isn't all lowercase (FreeBSD
).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
edit: add
OSTYPE
fallback for non-posix shells.