While working with the bash shell scripting, Many times you may require to get your system version or codename or operating system architecture. In this article, you will learn, how to find Ubuntu Version, Codename, and OS Architecture in a shell script.
1. Get Ubuntu Version
To get ubuntu version details, Use -r
with lsb_release
command.
$ lsb_release -r Release: 14.04
Also use -s
or --short
to get details in short format
$ lsb_release -r --short 14.04
2. Get Ubuntu Codename
To get ubuntu version details, Use -c
with lsb_release
command.
$ lsb_release -c Codename: trusty
Also use -s
or --short
to get details in short format
$ lsb_release -c --short trusty
3. Get OS Architecture Details
To find the operating system architecture details using uname
command with -m
parameter.
$ uname -m x86_64
4. Shell Script – Store Values in Variable
Now if we need to use these values in a shell script, store these values in variables. Below example, the shell script will help you to store the output of commands in variables and use them
#!/bin/bashVersion =$(lsb_release -r --short )Codename =$(lsb_release -c --short )OSArch =$(uname -m ) echo "Version = $Version " echo "Codename = $Codename " echo "OS Architecture = $OSArch "