我正在编写一个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
命令或其他东西上应用正则表达式?
谢谢..
发布于 2015-04-12 02:55:50
$ lsb_release -i
Distributor ID: Fedora
$ lsb_release -i | cut -f 2-
Fedora
发布于 2016-10-10 21:15:13
试试这个:
awk '/^ID=/' /etc/*-release | awk -F'=' '{ print tolower($2) }'
发布于 2016-12-15 02:58:37
DISTRO=$( cat /etc/*-release | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|nameyourdistro)' | uniq )
if [ -z $DISTRO ]; then
DISTRO='unknown'
fi
echo "Detected Linux distribution: $DISTRO"
https://stackoverflow.com/questions/29581754
复制相似问题