neocai 发表于 2018-8-18 12:37:18

判断centos系统版本的shell-chaichuan

  日常维护中,需要写个通用的执行shell,但是centos 6 版本与 7版本的诸多命令不同,需要程序自己判断,方法如下:
  1、查看cat /etc/centos-release
root@pts/0 # cat /etc/redhat-release|sed -r 's/.* (+)\..*/\1/'  
7
  
root@pts/15 # cat /etc/redhat-release|sed -r 's/.* (+)\..*/\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


页: [1]
查看完整版本: 判断centos系统版本的shell-chaichuan