Shell 简单判断系统类型

作者: ropon 分类: Shell 发布时间: 2018-10-05 09:38
#!/bin/bash
if [ -e /etc/redhat-release ]; then
	OS=CentOS
	[ -n "$(grep ' 7\.' /etc/redhat-release 2> /dev/null)" ] && OS_Ver=7
	[ -n "$(grep ' 6\.' /etc/redhat-release 2> /dev/null)" ] && OS_Ver=6
elif [ -n "$(grep -i 'Debian' /etc/issue 2> /dev/null)" ]; then
	OS=Debian
elif [ -n "$(grep -i 'Ubuntu' /etc/issue 2> /dev/null)" ]; then
	OS=Ubuntu
else
	echo "认不到此系统"
fi
echo $OS
echo $OS_Ver

 

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!