Command to Check if a software is installed on Ubuntu

Asked

Viewed 101 times

1

Script that checks if a software is installed on Ubuntu. If installed, continue with the command sequence. if you do not ask if the user wants to install it anyway

Example:

if (programa1=Instalado, programa2=instalado); then  
continua script;  
else  
echo "Voce precisa do programa1 e ele não está instalado, deseja continuar  
 assim mesmo?"  
"sim"  
continua script  
"não"  
Sai do script  

I know that by DEB can do this, using the control but I would like to use a script.

1 answer

2


Use the command command informing the argument -v

echo $(command -v git)

in the above example, if git was found will have a similar return to the below:

>> /usr/bin/git

otherwise it will return nothing.

>> 

Checking the return:

if ! [ -x "$(command -v git)" ]; then
    echo 'git não instalado.' >&2
    exit 1
else
    echo 'git instalado.'
fi

Behold running on tutorialspoint.com

Remember that it works on all systems that use the as a command interpreter.

Reference

Browser other questions tagged

You are not signed in. Login or sign up in order to post.