Saturday, February 19, 2022

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

Issue

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

The following lines were displayed,it is a shell script.

[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

To input echo $releasever in terminal,nothing output in the screen.

How to get the value of $releasever ,$arch,$basearch ?


Solution

These aren't shell variables, so you would not expect to be able to print them in bash. These are values that are provided by yum. This answer discusses how to get them programatically, but in general:

  • releasever is the major version of your CentOS release; basically, rpm -q --qf='%{VERSION}\n' centos-release
  • basearch is your system architecture, which you can find with uname -m
  • There is no arch variable
  • infra is apparently something new and may not be used, based on this post

There is some documentation here, which while old-ish is still accurate.



Answered By - larsks
Answer Checked By - Marilyn (WPSolving Volunteer)