静默检查bash脚本中是否存在rpm [英] Check if rpm exists in bash script silently
本文介绍了静默检查bash脚本中是否存在rpm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用if语句快速检查bash脚本中是否安装了rpm.但是我想安静地做.当前,当我运行脚本并且确实存在rpm时,它将rpm的输出输出到我不想要的屏幕上.
I'm trying to do a quick check to see if an rpm is installed in a bash script using an if statement. But I want to do it silently. Currently, when I run the script, and the rpm does exist, it outputs the output of rpm to the screen which I dont want.
if rpm -qa | grep glib; then
do something
fi
也许我错过了一个rpm选项?还是只需要更改我的声明?
Maybe there is an option to rpm that I am missing? or if I just need to change my statement?
谢谢
推荐答案
1)您可以将-q开关添加到grep
1) You can add -q switch to grep
if rpm -qa | grep -q glib; then
do something
fi
2)您可以将stout和/或stderr输出重定向到/dev/null
2) You can redirect stout and/or stderr output to /dev/null
if rpm -qa | grep glib 2>&1 > /dev/null; then
do something
fi
这篇关于静默检查bash脚本中是否存在rpm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文