Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find whether a library is installed using shell script

Tags:

linux

shell

deb

I'm complete noobs in shell script what i want is shell script that determine a list of library/package currently installed if not install them without user permission

What I want is to determine the library/package is currently installed or not in system

I'm aware of aptitude search command but I looking for a better solution

e.g I have define(in shell script) check for readline library/package now how can I from inside the shell script (I want to create) know that readline package is currently installed or not.

Any idea or suggestion would certainly help

like image 880
Viren Avatar asked Dec 28 '22 01:12

Viren


1 Answers

What I want is to determine the library/package is currently installed or not in system

dpkg -s does not require root permission, and will display package status details.

Example shell script:

#!/bin/sh

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

Usage is:

script.sh package1 package2 .... packageN

like image 168
Rony Avatar answered Jan 13 '23 13:01

Rony