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:
- You will have to deal with dependenciy issues while installing
- To avoid interaaction with script during install see here for examples.
- You can catch the return values from that function an use it to decide whether to install or not.