Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michael-milette/be0799b06c611fc46c8f4b6983eb4f9d to your computer and use it in GitHub Desktop.
Save michael-milette/be0799b06c611fc46c8f4b6983eb4f9d to your computer and use it in GitHub Desktop.
OS Detection in BASH
OS="$(uname -s)"
case "${OS}" in
Linux*) OS=Linux;;
Darwin*) OS=Mac;;
CYGWIN*) OS=Cygwin;;
MINGW*) OS=MinGw;;
*) if [[ -n "$IS_WSL" || -n "$WSL_DISTRO_NAME" ]]; then
OS="UNKNOWN:${OS}"
else
# WSL2
OTHEROS=$WSL_DISTRO_NAME
if [[ -n "$OTHEROS" ]]; then
# WSL1
OTHEROS=$WSL
fi
OS="UNKNOWN:${OS} / WSL:${OTHEROS}"
fi
esac
echo ${OS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment