参考一下How can I get distribution name and version number in a simple shell script?
其中被采纳的答案
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
OS=Debian # XXX or Ubuntu??
VER=$(cat /etc/debian_version)
elif [ -f /etc/redhat-release ]; then
# TODO add code for Red Hat and CentOS here
...
else
OS=$(uname -s)
VER=$(uname -r)
fi
参考一下How can I get distribution name and version number in a simple shell script?
其中被采纳的答案
稍微改改这段代码就可以了
如果系统可能性只有redhat和debian的话,可以执行yum --version然后判断执行结果。yum执行成功的话就redhar,不然就得采用上面那位同学的方法了。
look at this: