判断centos系统版本的shell

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断centos系统版本的shell相关的知识,希望对你有一定的参考价值。

日常维护中,需要写个通用的执行shell,但是centos 6 版本与 7版本的诸多命令不同,需要程序自己判断,方法如下:


 1、查看cat /etc/centos-release


[email protected]/0 # cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'
7
[email protected]/15 # cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'
6


2、查看rpm -q centos-release


[email protected]/0 # rpm -q centos-release|cut -d- -f3
7
[email protected]/15 # rpm -q centos-release|cut -d- -f3
6


以上是关于判断centos系统版本的shell的主要内容,如果未能解决你的问题,请参考以下文章