linux - 检测 linux 版本 5 或 6

标签 linux bash shell

<分区>

我是 shell 脚本的新手,因为我要检测 linux 的版本? 使用 shell 脚本将检测版本是 5 还是 6 Linux 如果可能的话使用 IF 执行安装 block 。

最佳答案

使用 lsb_release -r | cut -f2 以获得您的发行版? (并使用不同的分隔符再次 cut 以提取版本的主要编号)

例如:

version=`lsb_release -r | cut -f2 | cut -d. -f1`

if [ ${version} = 5 ]; then
    echo "This is version 5"
elif [ ${version} = 6 ]; then
    echo "This is version 6"
fi

关于linux - 检测 linux 版本 5 或 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21390196/

相关文章:

c++ - 如何编写命令行 shell 来捕获 'UP' 键以获取历史输入?

python kivy boxlayout设置位置

linux - 如何在 Linux 上将包含当前日期的文件名减去 1 天

linux - echo bash 中出现额外的百分号

c - 在 C 中实现 shell

linux - 从终端创建临时 Cron 作业

c++ - 如何检查一个进程是否正在运行或在 linux 中从我的 main() 中的 pid 在 linux 中终止

c++ - 在 Linux 中获取主板 deviceID 和 BIOS 序列号

bash - 使用两条指令运行 sed

bash - bash 中的 zip 文件夹