shell判断Linux发行版的命令

发布于 作者 [重庆SEO]

Markdown版本

下面的shell脚本函数引用自 lnmp1.2-full/include/main.sh
Get_Dist_Name()
{
    if grep -Eqi"CentOS" /etc/issue || grep -Eq"CentOS" /etc/*-release; then
        DISTRO='CentOS'
        PM='yum'
    elif grep -Eqi"Red Hat Enterprise Linux Server" /etc/issue || grep -Eq"Red Hat Enterprise Linux Server" /etc/*-release; then
        DISTRO='RHEL'
        PM='yum'
    elif grep -Eqi"Aliyun" /etc/issue || grep -Eq"Aliyun" /etc/*-release; then
        DISTRO='Aliyun'
        PM='yum'
    elif grep -Eqi"Fedora" /etc/issue || grep -Eq"Fedora" /etc/*-release; then
        DISTRO='Fedora'
        PM='yum'
    elif grep -Eqi"Debian" /etc/issue || grep -Eq"Debian" /etc/*-release; then
        DISTRO='Debian'
        PM='apt'
    elif grep -Eqi"Ubuntu" /etc/issue || grep -Eq"Ubuntu" /etc/*-release; then
        DISTRO='Ubuntu'
        PM='apt'
    elif grep -Eqi"Raspbian" /etc/issue || grep -Eq"Raspbian" /etc/*-release; then
        DISTRO='Raspbian'
        PM='apt'
    else
        DISTRO='unknow'
    fi
}
总结要点有:
1. cat /etc/issue
2. cat /etc/*-release
3. 哪些发行版使用yum 那些发行版使用apt
本文是否有所帮助?
点赞
说一说
打赏
支付宝支付支付宝
微信支付微信

多谢支持!