Onelinerhub
Posted on June 30, 2022
1. How to check if specific bash command is available:
if command -v CMD &> /dev/null; then echo "it exists"; fi
Edit or save this code on github.
2. How to check if specific file exists:
if [ -f /tmp/file ]; then echo 1; fi
Edit or save this code on github.
3. How to check if scecific directory exists:
if [ -d /tmp ]; then echo 1; fi
Edit or save this code on github.
4. How to check if variable is empty
if [ -z "$variable" ]; then echo "\$variable is empty"; fi
Edit or save this code on github.
5. How to check if variable is not empty
if [ ! -z "$variable" ]; then echo "\$variable is not empty"; fi
Edit or save this code on github.
💖 💪 🙅 🚩
Onelinerhub
Posted on June 30, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.