DEV Community

abbazs
abbazs

Posted on

1 1

How to get the ubuntu code name from elementary os?

Often when we try to install any software in elementary os using the terminal commands like the following:

wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install vagrant
Enter fullscreen mode Exit fullscreen mode

The script looks for a valid ubuntu version by executing lsb_release -cs. And it will return code name of elementary os but not the ubuntu code name. But what is required is ubuntu code name. The following script does not exactly solve the issue. But it is handy to fetch the ubuntu code and replace it where needed.

# Reads the /etc/os-release file and reads the file into a dictionary named os_release. 
# Please read https://unix.stackexchange.com/a/433245/298979 to understand why sourcing and awk are poor ideas to replicate the same in those methods.
if test -r /etc/os-release
    then
        declare -A os_release
        while IFS="\=" read -r key value
            do
                os_release[$key]=$value
        done < /etc/os-release
        alias uc="echo ${os_release[UBUNTU_CODENAME]}" #Get ubuntu code name
    else
        echo "Unable to read /etc/os-release file to get ubuntu code"
fi
Enter fullscreen mode Exit fullscreen mode

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay