I currently use this construction to check whether a certain program is installed:
if [ ! -e `which sqlite3` ]; then
cd /usr/ports/databases/sqlite3 && make install clean
else
echo "sqlite already installed"
fi
Is this method recommended? Is this an effective method, ie sufficiently robust for other examples, such as gcc, php, perl etc? Are there any caveats to this? The snippet is run as part of a script as root.
I don't think I'd recommend using 'which' in order to determine if software is installed - it is only going to see what is in the user's $PATH. rpm or other package managers can identify based on pattern matching.