How to check that if a package is installed?

J dreadpiratejeff at gmail.com
Tue Nov 30 14:17:14 UTC 2010


On Tue, Nov 30, 2010 at 07:54, S Mathias <smathias1972 at yahoo.com> wrote:
>
> if [ "$(dpkg -l | awk '/tofrodos/ && /^ii/ {print $2}' | awk '/^tofrodos/')" == "" ]; then echo -e "error: no zip package detected\!\n\nYou could install it like e.g.: \"apt-get install tofrodos\""; fi
>
>
>
>
> Is there a better way then this?
>
> Thank you!

dpkg -l |grep <package name>

or if you know the command from a given package, just try running it:
bladernr at klaatu:/media/TOSHIBA EXT$ fop
The program 'fop' is currently not installed.  You can install it by typing:
sudo apt-get install fop

Or do you mean programattically?

If programatically, then there's nothing wrong wtih what you have...
however, this is a little better:

mypackage=$2
 if [ "$(dpkg -l | awk '/$mypackage/ && /^ii/ {print $2}' | awk
'/^$mypackage/')" == "" ]; then echo -e "error: package $mypackage not
detected\!\n\nYou could install it like e.g.: \"apt-get install
$mypackage\""; fi

^^ that's a little more usable in general terms... but there are
better, or at least other, ways of doing this.




More information about the ubuntu-users mailing list