How to find Ubuntu Version, Codename and OS Architecture in Shell Script
Abstract: Codename=$(lsb_release -c --short)and OS Architecture in a shell script. 1. Get Ubuntu Version To get ubuntu version details
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 VersionTo 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.042. 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 trusty3. Get OS Architecture Details
To find the operating system architecture details using uname
command with -m
parameter.
$ uname -m x86_644. 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/bash Version=$(lsb_release -r --short) Codename=$(lsb_release -c --short) OSArch=$(uname -m) echo "Version = $Version" echo "Codename = $Codename" echo "OS Architecture = $OSArch"