【发布时间】:2023-01-17 21:08:00
【问题描述】:
该脚本应该能够检测到正在运行的操作系统。 可供选择的操作系统是 Arch Linux、Centos 和 Ubuntu。
os=$(uname)
if [ "$os" == "Arch" ]; then
echo "Arch Linux detected"
elif [ "$os" == "CentOS" ]; then
echo "CentOS detected"
elif [ "$os" == "Ubuntu" ]; then
echo "Ubuntu detected"
else
echo "Unknown OS detected"
fi```
Output: Unknown OS detected
I tried doing this:
\`del1()
{
os=$(cat /etc/os-release | grep "PRETTY_NAME")
}
del1
echo "The operating system is: $os"\`
The output: PRETTY_NAME="Ubuntu 20.04.2 LTS"
But I want to check between Centos, Arch Linux and Ubuntu.
Any suggestions?
【问题讨论】:
标签: bash ubuntu linux-kernel bash-completion