Skip to content

Instantly share code, notes, and snippets.

@corazzi
Last active March 21, 2017 10:12
Show Gist options
  • Save corazzi/955ca3ee12d7bfe926afb4fc21773655 to your computer and use it in GitHub Desktop.
Save corazzi/955ca3ee12d7bfe926afb4fc21773655 to your computer and use it in GitHub Desktop.
Determine the operating system from the command line
###########################################################
# 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