Quantcast
Channel: Script to check if some program is already installed - Ask Ubuntu
Viewing all articles
Browse latest Browse all 6

Answer by Elder Geek for Script to check if some program is already installed

$
0
0

Here's a function I wrote for the purpose that I use in my scripts. It checks to see if the required package is installed and if not, prompts the user to install it. It requires a package name as a parameter. If you don't know the name of the package a required program belongs to you can look it up. Information on that available here.

function getreq {
dpkg-query --show  "$1"
if [ "$?" = "0" ];
then
    echo "$1" found
else
    echo "$1" not found. Please approve installation.
    sudo apt-get install "$1"
    if [ "$?" = "0" ];
    then echo "$1" installed successfully.
    fi
fi
}

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>