shell判断Linux发行版的命令

发布于 分类 Linux

1天前 有1个用户阅读过

下面的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

-- The End --

本文标题: shell判断Linux发行版的命令

本文地址: https://seonoco.com/blog/shell-to-determine-the-linux-issue

点赞 0
感谢支持
0
多谢反馈
评论 0
打赏

支持微信/支付宝

评论

网友