Last active
February 4, 2025 17:33
-
-
Save htv2012/70a7d9c795c0cc2ecfd144abce7f5fc3 to your computer and use it in GitHub Desktop.
How to Detect Platform and Distro
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
# 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 |
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
#!/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