linux - 获取Centos版本的值

标签 linux bash shell awk sed

当我运行 cat/etc/redhat-release 时,我得到了输出

CentOS Linux 版本 7.5.1708

我只想从中得到值7

我已经写了下面的但是它不起作用

cat/etc/redhat-release | awk '{print $7}' | awk-F。 '{打印 $1}

最佳答案

如果你只想要数字,而不是 awk 的东西,这里有一个更简单的方法:

. /etc/os-release
echo $VERSION_ID

为什么?

查看手册页 man os-release

The basic file format of os-release is a newline-separated list of environment-like shell-compatible variable assignments. It is possible to source the configuration from shell scripts...

关于linux - 获取Centos版本的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49789770/

相关文章:

c - 如何获取目录中的目录数?

regex - 在执行搜索和替换操作后将文件移动到另一个文件夹

linux - bash 函数未能给出返回值

linux - 预计无法在我的 Bash 脚本中运行

linux - 使用 *nix 中的 column 命令格式化列表

linux - 我在哪里可以找到 request_irq 函数中的 IRQ 号?

c++ - 审核 bash RPG 的 bash 命令

BASH:查找并重命名文件和目录

c - 理解这个 shell 脚本分配

Linux:如何在别名中添加 $ 符号?