Check if rpm is installed

Hi all im hoping someone can help, i want to check if a rpm package is installed, if it is then display one text if not then another text, below is what i have got so far, im am very much a noob at this, as you can probably can see so if possible make it simple, and a big thankyou if you can help me please.

If its any help, a list of installed rpms is kept in /var/log/rpmpkgs
so i suppose its possible to check that instead of a rpm command but i havent a clue how to do that any help would be most grateful.

Hi.

Regrettably, rpm does not return an exit status as do most commands (more correctly it seems to always return zero). This might be because it's too complex to simply decide "yes" or "no".

So one solution is to look at the output. We can do a compare very similar to the way you did, but checking for a string match, rather than strict equality, which can cause problems because of whitespace, among other things.

Here's an example:

#!/bin/bash -

# @(#) user1    Demonstrate rpm query.

uname -rv
bash --version
rpm --version

echo
P=${1?" must specify package name."}

rpm -qa "$P" > t1
my_size=$( wc -l < t1 )
echo " Size of report file is $my_size lines"

if [[ $( rpm -qa $P ) =~ ${P} ]]
# if [[ $( rpm -qa $P ) == *${P}* ]]
then
  echo " Package $P is installed."
else
  echo " Package $P not found."
fi

exit 0

Producing a success:

./user1 bash
2.6.22.17-0.1-default #1 SMP 2008/02/10 20:01:04 UTC
GNU bash, version 3.2.25(1)-release (i586-suse-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
RPM version 4.4.2

 Size of report file is 1 lines
 Package bash is installed.

And a failure:

./user1 junk
2.6.22.17-0.1-default #1 SMP 2008/02/10 20:01:04 UTC
GNU bash, version 3.2.25(1)-release (i586-suse-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
RPM version 4.4.2

 Size of report file is 0 lines
 Package junk not found.

You can look a the output from rpm on file t1. Both forms of the "if" seemed to work for me, and you can look through man bash or a tutorial to see the details on the "if" ... cheers, drl

Thankyou so much,:b: this has helped me alot,if you are a beautiful woman then big hugs and kisses as well :smiley: if not then just a big thankyou:D