1

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 1

6

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)
1
  • 3
    If 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).
    – Zoredache
    Aug 23, 2018 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.