【问题标题】:How this command find a file in Rpm package此命令如何在 Rpm 包中查找文件
【发布时间】:2013-08-18 12:14:31
【问题描述】:

我已经给出了命令,该命令将在 insatlled 的一个 rpm 包中找到一个名为 /etc/limits 的特定文件,但是当在我的系统上运行时出现错误而不是预期的结果。下面是命令

find . -name '*.rpm' | while read A; do $RPM -qpl $A | grep etc/limits; \
if [ $? -eq 0 ]; then echo $A; fi; done
/etc/limits

当我运行这个命令时出现错误

bash: syntax error near unexpected token `/etc/limits'

谁能告诉我这里出了什么问题?

【问题讨论】:

  • 1.您说“已安装 rpm 包”,但您使用了 -p 标志,这意味着您正在搜索目录树中的 RPM(来自 .),而不是已安装的 RPM。 2. 要搜索已安装的 RPM,只需简单地做rpm -q --whatprovides /etc/limits

标签: linux shell command find rpm


【解决方案1】:

很明显,您的while 循环从find 获取输入,因此您不需要在脚本中的done 之后使用/etc/limits。说:

find . -name '*.rpm' | while read A; do
  $RPM -qpl $A | grep /etc/limits;
  if [ $? -eq 0 ]; then echo $A; fi;
done

应该可以。如果你想让while 循环从文件中读取,你会说:

while read A; do ... done < /path/to/input/file

【讨论】:

  • 感谢@devnull,但每当我发出这个命令时,它都会告诉我“bash: -qpl: command not found”,但 qpl 在我的机器上运行良好
  • 我以为你的脚本中有一个变量RPM,它被定义为RPM=rpm。如果不是这种情况,那么不要说$RPM,而是说rpm
  • 它现在正在工作,但我仍然无法缩小搜索范围,在完成所需的完整路径或 /etc/limit 后使用 /path/to/input/file 就足够了??
  • @AmitSinghTomar 我不确定你在问什么,但使用两种方法中的任何一种。不要通过管道传输到 while 并同时从文件中读取它。
  • 这是成功使用命令的地方,但对我来说它不起作用stackoverflow.com/questions/18228503/…
猜你喜欢
  • 2011-09-30
  • 2011-06-27
  • 2011-07-19
  • 2016-02-10
  • 1970-01-01
  • 2020-01-24
  • 2011-06-13
  • 2015-06-16
  • 2011-08-07
相关资源
最近更新 更多