如何获取centos7 repo文件中变量的值?

How to get the value of variables in centos7 repo file?

cat /etc/yum.repos.d/CentOS-Base.repo

显示了以下几行,这是一个shell脚本。

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

终端输入echo $releasever,屏幕无输出。

如何获取$releasever,$arch,$basearch的值?

这些不是 shell 变量,因此您不会期望能够在 bash 中打印它们。这些是由 yum 提供的值。 This answer 讨论如何以编程方式获取它们,但总的来说:

  • releasever 是您的 CentOS 发行版的主要版本;基本上,rpm -q --qf='%{VERSION}\n' centos-release
  • basearch是你的系统架构,你可以用uname -m
  • 找到
  • 没有arch变量
  • infra 显然是新东西,可能不会被使用,基于 this post

有一些文档 here,虽然过时但仍然准确。

你可以使用这个命令:

python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'