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
Source it and you can access the variable directly:
You may use
awk
:Using
lsb_release
is an ideal way to access distribution information. To get only the version, use:If
lsb_release
isn’t installed on your system (if I recall correctly) do: