Skip to content

Instantly share code, notes, and snippets.

@lynsei
Created December 26, 2024 16:00
Show Gist options
  • Save lynsei/a9d18d34b12d78cb96399f1b0aa5f614 to your computer and use it in GitHub Desktop.
Save lynsei/a9d18d34b12d78cb96399f1b0aa5f614 to your computer and use it in GitHub Desktop.
Detect operating system
#!/bin/bash
detect_os() {
local os="unknown"
case "$(uname -s)" in
Linux)
os="Linux"
;;
Darwin)
os="macOS"
;;
CYGWIN*|MINGW*|MSYS*|MINGW32*|MINGW64*)
os="Windows"
;;
FreeBSD)
os="FreeBSD"
;;
OpenBSD)
os="OpenBSD"
;;
NetBSD)
os="NetBSD"
;;
SunOS)
os="Solaris"
;;
AIX)
os="AIX"
;;
*)
# Fallback check for unknown or custom OS
os="unknown: $(uname -s)"
;;
esac
echo "$os"
}
# Call the function and output the result
detect_os
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment