Q:

apt - checking if a similar package has been installed

This question explains how to find out if a given Debian package has been installed, but it does not take into account "synonyms" when installing via apt-get.
For instance, if I try apt-get install libncurses-dev, apt-get replies:
Note, selecting 'libncurses5-dev' instead of 'libncurses-dev'

And then it installs that package (libncurses5-dev), which is fine by me. 
But what if I want to make a script to detect if the package has already been installed?
dpkg -s libncurses-dev replies that the package is not installed, which is indeed correct, since it's libncurses5-dev that was installed. But I'd like my script to detect that, in this case, it no longer needs to install libncurses-dev.
I could not find an option in apt-get to check if the given package or one of its providers has already been installed, such that my script would work when checking for libncurses-dev as well as for libncurses5-dev.

A:

If you want to write a script to check to see if package libncurses-dev or its alias has been installed, consider the following program flow:

Check if the package has been installed with dpkg using the exact name, libncurses-dev in this case.
If the above does not evaluate to true, then search apt for the package you are looking for using the non-aliased name:
$ apt-cache search libncurses-dev
libncurses5-dev - developer's libraries for ncurses

It appears that apt-cache search will return the 'alias' if the package has one.

If #1 evaluates false and #2 returns an alias, just grab the package's alias and try #1 again.

Check dpkg again with the alias name of the package, in this case it would be libncurses5-dev. If dpkg does not find the package by an alias (actually a superseded package) then it must not be installed.

