2

I execute command cat /etc/os-release in order to get info like

NAME="Ubuntu"
VERSION="18.04 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

I want to get only 18.04 from VERSION_ID

I tried like

cat /etc/os-release | grep VERSION_ID=

which returns

VERSION_ID="18.04"

I don't know how to take that version number. Can advice me how to do that ?

1
  • How about lsb_release -sr in Bash/Terminal? Commented Apr 21, 2020 at 14:29

3 Answers 3

7

Source it and you can access the variable directly:

. /etc/os-release
echo "$VERSION_ID"
Sign up to request clarification or add additional context in comments.

Comments

4

Using lsb_release is an ideal way to access distribution information. To get only the version, use:

lsb_release -sr

If lsb_release isn't installed on your system (if I recall correctly) do:

sudo apt-get install lsb-core

1 Comment

Should be provided with the installation of the OS version already. Didn't think my comment was worth an answer. :)
1

You may use awk:

awk -F= '$1 == "VERSION_ID" {gsub(/"/, "", $2); print $2}' /etc/os-release

18.04

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.