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

时间:2015-08-26 00:49:51

标签: bash centos7

[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

显示以下行,它是一个shell脚本。

echo $releasever

要在终端输入<?php if(isset($_POST["searchBtn"])) { $strInputSuburb = ""; $strInputStreet = ""; $strInputSuburb = $_POST["suburb"]; $strInputStreet = $_POST["street"]; if(!empty($strInputSuburb) || !empty($strInputStreet)) { $conn = @mysqli_connect("localhost", "example", "exmaple") or die ("Failed to connect server"); @mysqli_select_db($conn, "example") or die ("Database not available"); $querySql1 = "select * from Infringement where suburb like '%$strInputSuburb%' and street1 like '%$strInputStreet%' order by Fines($) acs";***// After adding this line, it always said: Problem Query*** $result1 = mysqli_query($conn, $querySql1) or die ("Problem Query...");.***// when I delete die function, it said cannot find the parameters.*** $count = mysqli_num_rows($result1); if(!count==0){ echo "<div class='table-responsive row' id='tableTop'>"; echo "<div class='col-md-10 col-md-offset-1'>"; echo "<table class='table table-bordered table-hover '>"; echo "<tr><th>Location</th><th>Suburb</th><th>No. of Infringements</th><th>Fines($)</th></tr>"; while($Row = mysqli_fetch_row($result1)){ echo "<tr><td>Intersection of ".$Row[1]." and ".$Row[2]."</td><td>".$Row[3]."</td><td>".$Row[4]."</td><td>".$Row[5]."</td></tr>"; } echo "</table>"; echo "</div>"; echo "</div>"; } else { echo "No data found! Please search again!"; } mysqli_free_result($result1); mysqli_close($conn); } else { echo "<div style='padding-top:9px;color:grey' class='col-md-3 col-md-offset-2'>"; echo "Please type any <b>Suburb</b> or <b>Street</b>."; echo "</div>"; } } ?> ,屏幕上没有任何输出。

如何获得$ releasever,$ arch,$ basearch的价值?

2 个答案:

答案 0 :(得分:3)

您可以使用此命令:

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

答案 1 :(得分:1)

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

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

有一些文档here,虽然旧的仍然准确。