Last active
March 21, 2017 10:12
-
-
Save corazzi/955ca3ee12d7bfe926afb4fc21773655 to your computer and use it in GitHub Desktop.
Determine the operating system from the command line
This file contains hidden or 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
########################################################### | |
# Determine the operating system from the command line | |
# | |
# NB: Only handles Ubuntu, CentOS, and MacOS so far | |
########################################################### | |
function which_os() { | |
# Setup an OSNAME variable to capture the OS's name | |
OSNAME='Unknown'; | |
# If there is an /etc/os-release file, use that | |
if [[ -f "/etc/os-release" ]] | |
then | |
OSINFO=`cat /etc/os-release`; | |
else | |
# Otherwise use the uname -a command | |
OSINFO=`uname -a` | |
fi | |
# Try and find the OS name in the OS info | |
case $OSINFO in | |
*'Ubuntu'*) | |
OSNAME='Ubuntu' | |
;; | |
*'CentOS'*) | |
OSNAME='CentOS' | |
;; | |
*'Darwin'*) | |
OSNAME='MacOS' | |
;; | |
esac | |
echo $OSNAME; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment