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

Re: How to check that if a package is installed?

Andrei Popescu wrote:
> Bob Proulx wrote:
> > Andrei Popescu wrote:
> > > You don't even need the 
> Do you read minds? This should have been "... the grep", but I stopped 
> to check the man page and then forgot to remove it ;)

I wondered about that part. :-)

> > > 'dpkg -l' is fine as well, if used properly ;)
> > > 
> > > $ dpkg -l tofrodos
> > > No packages found matching tofrodos.

I assumed you were talking about the return code being zero in that
case.  Meaning that you could do something like this:

  if dpkg -l tofrodos >/dev/null; then

That works to test if the package is completely unknown to dpkg.

  $ dpkg -l doesnotexist
  No packages found matching doesnotexist.
  $ echo $?


> > However that doesn't handle packages that had been installed but are
> > now removed but not purged leaving configuration files behind.
> You still need the grep,

Okay.  Sorry.  That part of the message had gotten lost!  :-)

> what I meant was that 'dpkg -l <package>' 
> should be the same as 'dpkg --status <package>'[1], but many people tend 
> to forget that -l takes a pattern and prefer to use grep to search for 
> the needed package.
> [1] they are actually both calls to dpkg-query(1)

Yes...  It is six of one and a half dozen of another.  But I find
grep'ing the "header"-like output most easy and straight forward.  It
just seems less cryptic and more self-documenting to look for
"Status: install ok installed" (which to me makes it very obvious what
is being looked for) than to look for "^ii " which although I know
what it is looking for I think is less obvious, if equivalent.


Attachment: signature.asc
Description: Digital signature

Reply to: