我正在编写一个shell脚本,在其中需要当前操作系统的名称以使其通用。例如:
if [ $Operating_System == "CentOS" ]
then
echo "CentOS";
# Do this
elif [ $Operating_System == "Ubuntu" ]
then
echo "Ubuntu";
# Do that
else
echo "Unsupported Operating System";
fi
如何实现呢?应该使用正则表达式对
lsb_release -a
命令进行匹配还是其他方法?谢谢。
lsb-release
绝对是最强大和通用的方法。例如:lsb_release -d|awk '{print $2}'
。 - FoggyDaylsb_release -ds
- Cyrus