How to get in a Bash script the simple lowercase name of the current Debian or Ubuntu release, e.g. stretch, jessie, xenial, artful?
1 Answer
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)
-
3If you are going to use lsb_release, use the command like arguments to give you the code name, instead of grepping and slicing the output.
NAME=$(lsb_release --codename --short)
. Aug 23, 2018 at 22:58