Creating Bash or Shell script for validating whether some command exists or not, can be necessary in some cases. Here I’m going to give you a quick example of how can you achieve it.
Prerequisites
- Linux
- sudo privileges
Solution
I’ve created a bash script that checks whether the telnet
command exists or not. There are two cases:
- If doesn’t exist proceed with the installation.
- If exist, print that.
#!/usr/bin/env bash
if ! command -v telnet &> /dev/null
then
echo "Telnet could not be found. Installing it ..."
# installation part
else
echo "Telnet is installed"
fi
Conclusion
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.