How to show Linux distribution command

I need to show Linux distribution and take certain action if it is CentOS. Is it possible in shell script and command line? Like if it is CentOS run ‘yum install mypak1’ but if not, say, your distribution is not supported at this time.

Run the following to get Linux distro name:

grep '^ID=' /etc/os-release

You will something as follows:


We can combine the grep command and sed command as follows to extract and store name to a shell variable such as my_os:

my_os=$(grep '^ID=' /etc/os-release  | sed 's/ID=//g; s/"//g')
echo "$my_os"



Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki