使用';grep搜索&x27;作为';yum更新';(Shell脚本)

使用';grep搜索&x27;作为';yum更新';(Shell脚本),shell,grep,yum,Shell,Grep,Yum,我的一位教授推荐我做这份学生工作。我一生中从未编写过shell脚本。我在网上读了一些关于shell脚本的教程,但仅此而已。无论如何,我被要求创建一个脚本,该脚本将运行: find-repos-of-install | grep rpmfusion 并给出该搜索的输出,将运行yum更新。例: find-repos-of-install | grep rpmfusion #that gives this output libCg-3.1.0013-2.el6.x86_64 from repo r

我的一位教授推荐我做这份学生工作。我一生中从未编写过shell脚本。我在网上读了一些关于shell脚本的教程,但仅此而已。无论如何,我被要求创建一个脚本,该脚本将运行:

find-repos-of-install | grep rpmfusion
并给出该搜索的输出,将运行yum更新。例:

find-repos-of-install | grep rpmfusion

#that gives this output
libCg-3.1.0013-2.el6.x86_64 from repo rpmfusion-nonfree-updates
pgplot-5.2.2-34.el6.1.x86_64 from repo rpmfusion-nonfree-updates
pgplot-devel-5.2.2-34.el6.1.x86_64 from repo rpmfusion-nonfree-updates

yum update libCg pgplot pgplot-devel

这就是他想要剧本做的。我不是要求任何人为我写整个剧本,只是试着给我指出正确的方向。我已经用Java编写了代码,但这对我一点帮助都没有,shell脚本对我来说仍然是胡言乱语。感谢您提供的提示

对于如何使用另一个命令(在您的情况下为grep)的输出调用命令(在您的情况下为yum),您有两个选项:一个是执行以下操作:

$ yum update $(find-repos-of-install | grep rpmfusion)
$ find-repos-of-install | grep rpmfusion | xargs yum update
另一种方法是使用
xargs
,类似于:

$ yum update $(find-repos-of-install | grep rpmfusion)
$ find-repos-of-install | grep rpmfusion | xargs yum update

太好了,谢谢。我最终选择了“$find repos of install | grep rpmfusion | xargs yum update-y”非常感谢好的,我很高兴能帮上忙。