DEV Community


Posted on

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- | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] $(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 to understand why sourcing and awk are poor ideas to replicate the same in those methods.
if test -r /etc/os-release
        declare -A os_release
        while IFS="\=" read -r key value
        done < /etc/os-release
        alias uc="echo ${os_release[UBUNTU_CODENAME]}" #Get ubuntu code name
        echo "Unable to read /etc/os-release file to get ubuntu code"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)