Skip to content

Instantly share code, notes, and snippets.

@htv2012
Last active February 4, 2025 17:33
Show Gist options
  • Save htv2012/70a7d9c795c0cc2ecfd144abce7f5fc3 to your computer and use it in GitHub Desktop.
Save htv2012/70a7d9c795c0cc2ecfd144abce7f5fc3 to your computer and use it in GitHub Desktop.
How to Detect Platform and Distro
# Detect platform in bash
# https://stackoverflow.com/a/3466183/459745
case $(uname -s) in
Linux*) platform=Linux;;
Darwin*) platform=Mac;;
CYGWIN*) platform=Cygwin;;
MINGW*) platform=MinGw;;
*) platform=Unknown;;
esac
echo Platform is $platform
#!/bin/sh
# Determine the distro and return a lower-case string
# Here are some known OSes:
# - On Fedora: fedora
# - On FreeBSD or GhostBSD: freebsd
# - On Linux Mint and LMDE: linuxmint
# - On Mac: darwin
# - On PopOS: pop
# - On Raspbian: raspbian
# - On Ubuntu: ubuntu
get_distro() {
if [ -f /etc/os-release ]
then
# On Linux systems
sed -n '/^ID=/s/ID=//p' /etc/os-release
else
# On systems other than Linux (e.g. Mac or FreeBSD)
uname
fi | tr '[:upper:]' '[:lower:]'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment