Find if a library is installed using a shell script

I have a complete noobs in a shell script, what I want is a shell script that defines a list of currently installed libraries / packages if they are not installed without user permission.

What I want is to determine if the library / package is installed or not on the system

I know the aptitude search command, but I'm looking for a better solution

For example, I have a definition (in a shell script) to check the readline library / package, how I can inside the shell script (I want to create) know that the readline package is currently installed or not.

Any idea or suggestion will certainly help.

+4
source share
4 answers

What I want is to determine if the library / package is installed or not on the system

dpkg -s does not require root privileges and displays package status information.

Shell example script:

 #!/bin/sh for P; do dpkg -s "$P" >/dev/null 2>&1 && { echo "$P is installed." } || { echo "$P is not installed." } done 

Using:

script.sh package1 package2 .... packageN

+8
source

For a simple test run, it seems that you could grep the output of a command, such as ldconfig -p, for the library you are interested in.

Or you can provide a tiny test program associated with the desired library, try to run it and test it without crashing.

+2
source

If you are trying to configure dependency checking, the correct solution is to create a dummy package that Depends: on the packages you need to install. There is a tool called equivs that somewhat helps with this. (However, it was criticized as being β€œover-engineered,” of course, if you are familiar with the Debian package format, you may not need a separate tool if your requirements are simple.) Then you just install this package and it will pull the packages that are specified as dependencies.

You still need to know that the library that provides libreadline.so is libreadline5-dev . Finding a Debian package can help you find the package names you need to put in Depends:

0
source

Maybe you can do what you want, dpkg

-1
source

Source: https://habr.com/ru/post/1412213/


All Articles