The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 16,793β€…    Votes:  27β€…    βœ… Solution
Tags: command-line   bash   scripts  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1162492
Title: How can you tell the version of Ubuntu on a system in a .sh (bash) script?
ID: /2019/07/31/How-can-you-tell-the-version-of-Ubuntu-on-a-system-in-a-.sh-_bash_-script_
Created: July 31, 2019    Edited:  August 1, 2019
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


Var=$(lsb_release -r)
echo "$Var"

Should do the trick.

For the numeric portion only add this:

NumOnly=$(cut -f2 <<< "$Var")
echo "$NumOnly"

The lsb-release variables file

/usr/bin/lsb_release is a Python script. It’s a short script that serves as a good introduction to the python language. As others mentioned, a shorter way to get the version number only is with lsb_release -sr.

The /etc/lsb-release file defines environmental variables with the same information provided by the lsb_release -a command:

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"

You can include these environment variables at anytime using . /etc/lsb-release. To test in your terminal:

$ . /etc/lsb-release

$ echo $DISTRIB_RELEASE
16.04

$ echo $DISTRIB_DESCRIPTION
Ubuntu 16.04.6 LTS
⇧ WSL: Is there a conditional to detect "Open Linux Shell Here" case? How to get CPU-G to run on 18.04  β‡©