[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Checking for installed package



On 25/05/13 06:30, Kip Warner wrote:
Hey list,

I'd like to know the most reliable way for a bash script to verify that
a package is installed on the user's system. I've looked already at
dpkg, dpkg-query, and aptitude. These are the constraints:

         1. It needs to work on any stock Debian based system, e.g.
         aptitude not always present, so can't rely on it.

         2. It needs to be i18n safe, e.g. no reliance on grepping for
         "Installed:" output of apt-cache policy<package>  because that
         is en locale specific.

         3. It needs to be able to distinguish a package that is
         installed from any other condition with only the former we care
         about. That means the exit code, for instance, of the query
         should be never be the same for a package that is installed
         versus one that is not installed - and not available anywhere.

Any help appreciated.


LANGUAGE="C" dpkg -l $packagename | grep -q "^ii "

will return 0 if the package is installed and 1 for any other state.

--
Dom


Reply to: