How to get in a Bash script the simple lowercase name of the current Debian or Ubuntu release, e.g. stretch, jessie, xenial, artful?
It's available in
/etc/os-release, but it's inconsistent between Ubuntu and Debian. Documentation isn't very specific on how to use it.
. /etc/os-release NAME=$VERSION_CODENAME if [ -z "$NAME" ]; then NAME=$(echo $VERSION | sed -rn 's|.+\((.+)\).+|\1|p') fi
It's also available in the command
lsb_release, which, when installed, needs no parsing:
NAME=$(lsb_release --codename --short)
Finally, it can be obtained directly from the sources file with some heavy-ish parsing.
NAME=$(sed -rn 's|^deb\s+\S+\s+(\w+)\s+main.*$|\1|p' /etc/apt/sources.list | head -n 1)