test if command exist/is installed

test if command is installed

hash ls && echo installed || echo not installed

type ls &> /dev/null && echo installed || echo not installed

test if command isn’t installed

! hash ls7 &> /dev/null && echo not installed

! type ls7 &> /dev/null && echo not installed

test a single command

if ! type sshpass &> /dev/null; then
  echo -e "\e[31;1m[ ERRO ]\e[m sshpass installed!"
  exit
fi

testing multiple commands

if ! type sshpass &> /dev/null || ! type bc &> /dev/null; then
  echo -e "\e[31;1m[ ERRO ]\e[m: sshpass or bc not installed!"
  exit
fi

Leave a comment