Skip to content

Instantly share code, notes, and snippets.

@jargnar
Last active April 12, 2016 07:31
Show Gist options
  • Save jargnar/6f72f49b3fc86df0816f0aae21967806 to your computer and use it in GitHub Desktop.
Save jargnar/6f72f49b3fc86df0816f0aae21967806 to your computer and use it in GitHub Desktop.
Check if a command exists in linux
#!/bin/bash
if [ $# -eq 0 ]; then
printf "Please specify the command to check for.\n"
printf "Example:\n"
printf "$ ./checkcmd.sh docker\n"
else
if sudo command -v $1 >/dev/null 2>&1; then
printf "Yay! $1 exists.\n"
else
printf "Noo! $1 is not available.\n"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment