skip to Main Content

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 ?

3

Answers


  1. Source it and you can access the variable directly:

    . /etc/os-release
    echo "$VERSION_ID"
    
    Login or Signup to reply.
  2. You may use awk:

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

    18.04
    
    Login or Signup to reply.
  3. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search