检查linux版本的更好方法? [英] Better way to check linux version?

查看:58
本文介绍了检查linux版本的更好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前拥有的.这是最好的方法吗?拥有一个具有很多功能的脚本,并且需要一种在运行每个功能之前知道正在运行什么操作系统的方法.

What I currently have. Is this the best way? Have a script with lots of functions and need a way to know what OS is running before running each function.

CHECK_architecture()
{
    architecture=`uname -m`
    if [ "$architecture" != "x86_64" ] && [ "$architecture" != "ia64" ]; then
        architecture="x86"
    else
        architecture="x86_64"
    fi
}
CHECK_distro()
{
    DISTRO="";
    if [ `uname -r | egrep '(6.2-RELEASE|6.1-RELEASE|5.5-RELEASE|6.1-STABLE|5.4-RELEASE|6.0-RELEASE|5.3-RELEASE|4.10-RELEASE|4.11-RELEASE)'` ]; then
        DISTRO="FreeBSD";
        $BIN_ECHO " System is running FreeBSD"
    elif [ -f /etc/debian_version ];  then 
           $BIN_ECHO " System is running Debian Linux"
           DISTRO=DEBIAN;
    elif [ -f /etc/SuSE-release ]; then
           $BIN_ECHO " System is running SuSE Linux"
           DISTRO=SUSE;
    elif [ -f /etc/fedora-release ]; then
           $BIN_ECHO " System is running Fedora Linux"  
          DISTRO=FEDORA;
    elif [ -f /etc/redhat-release ]; then
           $BIN_ECHO " System is running Red Hat Linux"
           DISTRO=REDHAT;
    else 
        $BIN_ECHO -e " no supported distribution found running "
    exit 1
fi
}

推荐答案

来自 Linux标准库维基百科上的文章:

From the Linux Standard Base article at wikipedia:

Linux Standard Base(LSB)是Linux基金会组织结构下的几个Linux发行版的联合项目,用于标准化与Linux操作系统一起使用的软件系统结构,包括文件系统层次结构.LSB基于POSIX规范,Single UNIX规范和其他几个开放标准,但是在某些方面进行了扩展.

The Linux Standard Base (LSB) is a joint project by several Linux distributions under the organizational structure of the Linux Foundation to standardize the software system structure, including the filesystem hierarchy, used with Linux operating system. The LSB is based on the POSIX specification, the Single UNIX Specification, and several other open standards, but extends them in certain areas.

根据LSB:LSB的目标是开发和推广一套开放标准,这些标准将提高Linux发行版之间的兼容性,并使软件应用程序即使在二进制格式下也可以在任何兼容的系统上运行.此外,LSB将帮助协调招募软件供应商以移植和编写Linux操作系统产品的工作.

According to the LSB: The goal of the LSB is to develop and promote a set of open standards that will increase compatibility among Linux distributions and enable software applications to run on any compliant system even in binary form. In addition, the LSB will help coordinate efforts to recruit software vendors to port and write products for Linux Operating System.

如果您使用的是 LSB 兼容发行版(并且应该使用),则只需 man lsb_release :

If you are using some LSB compliant distribution (and you should), just man lsb_release:

 $ lsb_release -a
 No LSB modules are available.
 Distributor ID: Ubuntu
 Description:    Ubuntu 8.04.4 LTS
 Release:        8.04
 Codename:       hardy


 $ lsb_release -a
 LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
 Distributor ID: CentOS
 Description:    CentOS release 5.5 (Final)
 Release:        5.5
 Codename:       Final

这篇关于检查linux版本的更好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆