How to check if a Command Exists using Bash Script

If you want to check if a command exists or not using a bash script, you can take help from the below example.



if command -v ls >/dev/null 2>&1; then
    echo "Command ls exists."
    echo "Command ls does not exist."

if command -v clean >/dev/null 2>&1; then
    echo "Command clean exists."
    echo "Command clean does not exist."

Command ls exists.
Command clean does not exist.
Check if Command Exists bash Example

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap