There is an interesting option --quiet available for the rpm command. The Man page says:
--quiet Print as little as possible - normally only error messages will be displayed.
So you can probably use this:
if rpm -q --quiet glib ; then do something fi
This path should be faster because it does not need to wait for the -qa (request of all) rpm packages to be installed, but simply asks for the target rpm package. Of course, you must know the correct name of the package you want to test if it is installed or not.
Note: Using RPM version 4.9.1.2 on Fedora 15
source share