Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Last active January 19, 2024 09:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmolveau/d0e3efc219c5bcc6ecc13a1405ac6c73 to your computer and use it in GitHub Desktop.
Save gmolveau/d0e3efc219c5bcc6ecc13a1405ac6c73 to your computer and use it in GitHub Desktop.
Bash/shell script detect/check OS and distribution (+WSL Windows Subsystem for Linux)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
local DISTRIB=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
if [[ ${DISTRIB} = "Ubuntu"* ]]; then
if uname -a | grep -q '^Linux.*Microsoft'; then
# ubuntu via WSL Windows Subsystem for Linux
else
# native ubuntu
fi
elif [[ ${DISTRIB} = "Debian"* ]]; then
# debian
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS OSX
fi
@ameeno
Copy link

ameeno commented Oct 25, 2022

Good stuff, However, I had an issue with SteamOS. it detects as "SteamOS" and won't load. fixed it by putting an asterisk in front of the OS Name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment