【发布时间】:2015-06-17 08:55:53
【问题描述】:
我正在编写一个 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}'. -
或
lsb_release -ds -
lsb_release 在 CENTOS7 上似乎不可用。
标签: regex linux bash shell operating-system