Distinguish between redhat and centos to get the release number command?

1. Problem: distinguish between redhat and centos to get release number (such as centos6.5 "6.5", redhat" 7.3")

2. I tried to write a command: lsb_release-a | grep Release | awk"{print $2}"| awk-F. "{print $1 "." $2}"
but only for centos6.5,redhat6.5, while the redhat7.3,centos7.3,lsb_release command does not apply to
clipboard.png

3. I also know that you can also use cat / etc/centos-release and cat / etc/redhat-release to check the release number
, but how do you distinguish between centos and redhat with the command? And get the release number

4. Just started to learn the script, is there any divine guidance, or other commands can also be implemented, thank you very much

May.23,2022

now that you know that centos will have / etc/centos-release,redhat will have / etc/redhat-release, just judge whether the file exists

[- f / etc/centos-release] & & echo centos


answer:
if [- e / etc/centos-release]; then

system=centos

elif [- e / etc/redhat-release]; then

system=redhat

else

echo "Other liunx versions"
exit 1

fi
version= cat / etc/$system-release | awk'{print $(NF-1)}'| awk-F. '{print $1 "." $2}'
echo $version

Menu