Skip to content

Instantly share code, notes, and snippets.

@montanaflynn
Last active July 15, 2024 11:41
Show Gist options
  • Save montanaflynn/e1e754784749fd2aaca7 to your computer and use it in GitHub Desktop.
Save montanaflynn/e1e754784749fd2aaca7 to your computer and use it in GitHub Desktop.
Checking for dependencies in a shell script
# Easy way to check for dependencies
checkfor () {
command -v $1 >/dev/null 2>&1 || {
echo >&2 "$1 required";
exit 1;
}
}
checkfor "ffmpeg"
# example using an array of dependencies
array=( "convert" "ffmpeg" )
for i in "${array[@]}"
do
command -v $i >/dev/null 2>&1 || {
echo >&2 "$i required";
exit 1;
}
done
@montanaflynn
Copy link
Author

@yoavz1997 thanks, updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment