I have these 2 functions on bash;
function ask_yes_or_no() {
read -p "$1 ([y]es or [N]o): "
case $(echo $REPLY | tr '[A-Z]' '[a-z]') in
y|yes) echo "yes" ;;
*) echo "no" ;;
esac
}
and
function is_it_installed()
{
i=0; n=0; progs=($@);
for p in "${progs[@]}"; do
if hash "$p" &>/dev/null
then
echo "$p is installed"
let c++
else
echo "'$p' is not installed. Do you want to install '$p'"
if [[ "yes" == $(ask_yes_or_no "Are you sure?") ]]
then
apt-get install $p
else
echo="Skipped installation of: '$p'"
# exit 1
fi
let n++
fi
done
printf "%d of %d programs were installed.\n" "$i" "${#progs[@]}"
printf "%d of %d programs were missing\n" "$n" "${#progs[@]}"
}
And I call this from another bashscript. But I would like to be able to set a status (or similar) to check if for example "mail" is installed, then "mail"s status should be 1, which I then can use in another check in the script using the function; something like this:
if [mail = 1]; then
do something
else something else
fi