Skip to content

Instantly share code, notes, and snippets.

@garygan89
Created December 14, 2022 07:27
Show Gist options
  • Save garygan89/ed9e6ccc813ed42348c3795e52a9ad3f to your computer and use it in GitHub Desktop.
Save garygan89/ed9e6ccc813ed42348c3795e52a9ad3f to your computer and use it in GitHub Desktop.
bash script to check if a command exist
# check if a program exist
#!/bin/bash
install_j2cli() {
echo -n "Installing j2cli Python module globally..."
sudo apt update && sudo pip3 install j2cli --system
check_exist j2
}
check_exist() {
PROG_NAME="${1}"
echo -n "Checking if ${PROG_NAME} exist..."
[ $(command -v ${PROG_NAME}) ] && { echo "OK"; exit 0; } || install_j2cli
}
check_exist j2
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment