Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以通过查看获得 5.8 或 6.4 数字/etc/redhat-release,但我不知道如何将其从 转换5.8为 just 5。到目前为止我使用的命令是:
/etc/redhat-release
5.8
5
cat /etc/redhat-release | awk {'print $7'}
产生5.8. 我将如何使用 bash 从中获取个位数整数?
或使用int()功能:
int()
cat /etc/redhat-release | awk '{print int($7)}' $ cat /etc/redhat-release | awk {'print $7'} 5.8 $ cat /etc/redhat-release | awk '{print int($7)}' 5
添加格式说明符:
cat /etc/redhat-release | awk '{printf "%d", $7}'