如何在Shell脚本中查看Ubuntu系统版本,代号和操作系统架构

时间:2019-05-19 01:26:17  来源:igfitidea点击:

在使用bash shell脚本时,很多时候我们可能需要获得系统版本或代号或操作系统架构。
在本文中,我们将学习如何在shell脚本中查找Ubuntu版本、代号和操作系统架构。

获取Ubuntu版本

要获得ubuntu版本的详细信息,使用' -r '和' lsb_release '命令。

$ lsb_release -r

Release:	14.04

也可以用“-s”或者“-short”来获得简短的详细信息

$ lsb_release -r --short

14.04

获取Ubuntu代号

要获得ubuntu版本的详细信息,使用' -c '和' lsb_release '命令。

$ lsb_release -c

Codename:	trusty

也可以用“-s”或者“-short”来获得简短的详细信息

$ lsb_release -c --short

trusty

获取OS架构信息

使用带“-m”参数的“uname”命令查找操作系统架构细节。

$ uname -m

x86_64

Shell脚本—将版本信息值存储到变量

现在,如果我们需要在shell脚本中使用这些值,请将这些值存储在变量中。
下面的示例shell脚本将在变量中存储命令的输出并使用它们

#!/bin/bash

Version=$(<orange>lsb_release -r --short)
Codename=$(<orange>lsb_release -c --short)
OSArch=$(<orange>uname -m)

echo "Version = $Version"
echo "Codename = $Codename"
echo "OS Architecture = $OSArch"