S
S
Sergey2018-12-02 11:31:34
linux
Sergey, 2018-12-02 11:31:34

How to check OS version in bash?

Good morning. Please tell me how to check the name of the distribution and its version in the .sh file.
For example: If the name of the distribution is Debian and its version is 7, then .sh should download one file.
And if the name of the distribution is CentOS and its version is 7, then the second file should be downloaded.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2018-12-02
@t3g1ng

cat /etc/*-release
This is a small bash script.

#!/bin/bash 
RELISE=`cat /etc/*-release| tr "\n" " "`

for name in 'CENTOS' 'UBUNTU' 'DEBIAN'
do
        echo $RELISE | grep -i -q $name && echo "OS name is $name"
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question