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
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
Top comments (0)