Skip to content

Instantly share code, notes, and snippets.

@ergoz
Forked from gmolveau/os.sh
Created June 23, 2025 13:48
Show Gist options
  • Save ergoz/1f69b121cce1f3bde54ac7af66efe081 to your computer and use it in GitHub Desktop.
Save ergoz/1f69b121cce1f3bde54ac7af66efe081 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment