通过shell判断操作系统发行版
2019-07-07 本文已影响0人
已不再更新_转移到qiita
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [ -f /etc/redhat-release ]; then
echo "Redhat Linux detected."
elif [ -f /etc/SuSE-release ]; then
echo "Suse Linux detected."
elif [ -f /etc/arch-release ]; then
echo "Arch Linux detected."
elif [ -f /etc/mandrake-release ]; then
echo "Mandrake Linux detected."
elif [ -f /etc/debian_version ]; then
echo "Ubuntu/Debian Linux detected."
else
echo "Unknown Linux distribution."
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Mac OS (Darwin) detected."
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo "FreeBSD detected."
else
echo "Unknown operating system."
fi