Scripts that need to know the distribution often grep through lsb_release output or /etc/issue. There is a cleaner way: /etc/os-release is written as shell variables, on purpose.
. /etc/os-release
echo "$ID $VERSION_ID $VERSION_CODENAME"
On Ubuntu 24.04 that prints ubuntu 24.04 noble. The os-release man page says the file is designed to be sourced by shell scripts, and lists the fields. ID is a short lowercase name such as debian, ubuntu or fedora. ID_LIKE lists related distributions, which is handy when you want one branch for the whole Debian family:
. /etc/os-release
case " $ID $ID_LIKE " in
*" debian "*) sudo apt-get install -y curl ;;
*" fedora "*|*" rhel "*) sudo dnf install -y curl ;;
esac
I prefer this over lsb_release, which is not installed on many minimal systems and containers.
Sourcing the file puts all its variables into your shell, including generic names like NAME and VERSION. In a larger script that can overwrite a variable you already use. Run it in a subshell, for example ID=$( . /etc/os-release; echo "$ID" ), if you only need one value. Some systems keep the real file in /usr/lib/os-release, with /etc/os-release as a link; the man page says to fall back to that path when the first one is missing.
Further reading: os-release(5) manual page