1. 程式人生 > >判斷centos系統版本的shell

判斷centos系統版本的shell

font cat 但是 back hat cut 12px sed ans

日常維護中,需要寫個通用的執行shell,但是centos 6 版本與 7版本的諸多命令不同,需要程序自己判斷,方法如下:


1、查看cat /etc/centos-release


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


2、查看rpm -q centos-release


root@pts/0 # rpm -q centos-release|cut -d- -f3
7
root@pts/15 # rpm -q centos-release|cut -d- -f3
6


判斷centos系統版本的shell