Find the answer to your Linux question:
Results 1 to 2 of 2
Within a bash script, how can I determine if an RPM is installed? I could parse the output of running the "rpm -q <package" command, but I don't know how ...
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    32

    BASH: Checking for installed RPM

    Within a bash script, how can I determine if an RPM is installed? I could parse the output of running the "rpm -q <package" command, but I don't know how to get the output into a variable or something. I don't really wanna' have to send it to a file, and read it.

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    you could check for return values
    Code:
    # rpm -q test
    package test is not installed
    # echo $?
    1
    # rpm -q coreutils
    coreutils-5.93-20
    # echo $?
    0
    or you could grep "not installed"
    if you want to put into variable:
    Code:
    # var=`rpm -q coreutils`
    # echo $var
    coreutils-5.93-20
     # var=`rpm -q test`
    # echo $var
    package test is not installed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...