I am writing a shell script in which I need the current operating system name to make it generic. Like:
if [ $Operating_System == "CentOS" ]
then
echo "CentOS";
# Do this
elif [ $Operating_System == "Ubuntu" ]
then
echo "Ubuntu";
# Do that
else
echo "Unsupported Operating System";
fi
How will it be possible? Applying regular expression on lsb_release -a
command or something else?
Thanks..
Open a terminal program (get to a command prompt) and type uname -a. This will give you your kernel version, but might not mention the distribution your running. To find out what distribution of linux your running (Ex. Ubuntu) try lsb_release -a or cat /etc/*release or cat /etc/issue* or cat /proc/version.
Open the terminal using “Show Applications” or with the keyboard shortcut [Ctrl] + [Alt] + [T]. Type the command “cat /etc/lsb-release” into the command line and press enter. The terminal shows the Ubuntu version you're running under “DISTRIB_RELEASE” and “DISTRIB_DESCRIPTION”.
The best way to determine a Linux distribution name and release version information is using cat /etc/os-release command, which works on almost all Linux system.
$ lsb_release -i
Distributor ID: Fedora
$ lsb_release -i | cut -f 2-
Fedora
You can get the info from lsb_release
:
echo "$(lsb_release -is)"
i
stands for distributor id.
s
stands for short.
For ex. It shows Ubuntu
instead of Distributor Id: Ubuntu
There are other options:
-r : release
-d : description
-c : codename
-a : all
You can get this information by running lsb_release --help
or man lsb_release
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With