当我运行 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/