Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if rpm exists in bash script silently

Tags:

bash

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

Maybe there is an option to rpm that I am missing? or if I just need to change my statement?

THanks

like image 290
Danny Avatar asked Nov 10 '11 18:11

Danny


1 Answers

1) You can add -q switch to grep

if rpm -qa | grep -q glib; then
  do something
fi

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
like image 191
vromanov Avatar answered Nov 10 '22 09:11

vromanov