Created
December 26, 2024 16:00
-
-
Save lynsei/a9d18d34b12d78cb96399f1b0aa5f614 to your computer and use it in GitHub Desktop.
Detect operating system
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/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