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

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

$
0
0

you can do this:

dpkg -s <packagename> &> /dev/null

then check exit status.only if the exit status of the above command was equal to 0 then the package installed.

so:

   #!/bin/bash

    echo "enter your package name"
    read name

    dpkg -s $name &> /dev/null  

    if [ $? -ne 0 ]

        then
            echo "not installed"  
            sudo apt-get update
            sudo apt-get install $name

        else
            echo    "installed"
    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>