Dup Ver Goto 📝

GetDistroName

PT2/linux/general/os does not exist
To
51 lines, 156 words, 1369 chars Page 'GetDistroName' does not exist.

On a typical Ubuntu system, /etc/issue contains

Ubuntu 22.04.1 LTS \n \l

so cat /etc/issue tells you all you need to know. On Fedora/Rocky (and presumably RHEL, but I'm not wealthy enough to test), it contains

\S
Kernel \r on an \m (\l)

which is not much help. What does \S expand to?

The information you want is in /etc/os-release. For example

NAME="Fedora Linux"
VERSION="38 (KDE Plasma)"
ID=fedora
VERSION_ID=38
VERSION_CODENAME=""
PLATFORM_ID="platform:f38"
PRETTY_NAME="Fedora Linux 38 (KDE Plasma)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:38"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f38/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=38
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=38
SUPPORT_END=2024-05-14
VARIANT="KDE Plasma"
VARIANT_ID=kde

So we know this is fedora. Note that we can source this as a shell script. Then we can do for example

( . /etc/os-release; echo "$PRETTY_NAME"; )

or even define

os_detail() { ( . /etc/os-release; echo "${!1}"; ); }

so that we can do

os_detail NAME

to get the os name.