Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Possible Duplicate:
How can I check if a package is installed (no superuser privileges)

I want a shell script method to test/report if a package is installed. I don't need details, only a yes/no.

I've come up with this method. Is there a more direct way?

is_installed=0
test_installed=( `apt-cache policy domy-ce | grep Installed: ` )
[ ! "${test_installed[1]}" == "(none)" ] && is_installed=1
share|improve this question

marked as duplicate by Takkat, jokerdino, Jacob Johan Edwards, Alvar, fossfreedom May 22 '12 at 18:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
This post should help you- stackoverflow.com/questions/1298066/… –  saji89 May 22 '12 at 7:18
    
Thanks saji89. The apparent duplicate gives accurate results with Debian registered packages, the results are unreliable on Ubuntu PPA packages. With packages that are registered on the host but not installed, dpkg's returncode is zero [0]. –  tahoar May 23 '12 at 13:04

1 Answer 1

You could use the output of dpkg -s <packagename> or dpkg-query -l <packagename>

in your script for the purpose.
Courtesy:http://stackoverflow.com/questions/1298066/check-if-a-package-is-installed-and-then-install-it-if-its-not

e.g.

#!/bin/sh

for P; do
    dpkg -s "$P" >/dev/null 2>&1 && {
        echo "$P is installed."
    } || {
        echo "$P is not installed."
    }
done

Usage: script.sh package1 package2 .... packageN

Courtesy:http://stackoverflow.com/a/10594734/749232

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.