I\'m working on a Ubuntu system and currently this is what I\'m doing:
if ! which command > /dev/null; then
echo -e \"Command not found! Install? (y/n)
I offer this update since Ubuntu added its "Personal Package Archive" (PPA) just as this question was answered, and PPA packages have a different result.
Native Debian repository package not installed:
~$ dpkg-query -l apache-perl
~$ echo $?
1
PPA package registered on host and installed:
~$ dpkg-query -l libreoffice
~$ echo $?
0
PPA package registered on host but not installed:
~$ dpkg-query -l domy-ce
~$ echo $?
0
~$ sudo apt-get remove domy-ce
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package domy-ce is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Also posted on: https://superuser.com/questions/427318/test-if-a-package-is-installed-in-apt/427898