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

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

$
0
0

This line of command will check using the which program and will return 0 if installed and 1 if not:

which apache | grep -o apache > /dev/null &&  echo 0 || echo 1

Of course you will use it in this manner in your script:

which "$1" | grep -o "$1" > /dev/null &&  echo "Installed!" || echo "Not Installed!"

A simple usage would be:

#!/usr/bin/env bash
set -e

function checker() { 
        which "$1" | grep -o "$1" > /dev/null &&  return 0 || return 1 
}

if checker "$1" == 0 ; then echo "Installed"; else echo "Not Installed!"; fi

Note several things:

  1. You will have to deal with dependenciy issues while installing
  2. To avoid interaaction with script during install see here for examples.
  3. You can catch the return values from that function an use it to decide whether to install or not.

Viewing all articles
Browse latest Browse all 6

Trending Articles



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