How to check if a program exists from a Bash/Shell script

You can look to use: command -v <the_command> There are also 2 other ways, that we will run through a little further down, but for now.. How to use the command if a conditional if ! command -v <the_command> &> /dev/null then echo "<the_command> could not be found" exit fi To summarize, there are 3 ways you can do this Option 1 - Using command command -v foo >/dev/null 2>&1 || { echo >&2 "foo is not installed....

April 18, 2023 · 1 min · 123 words · Andrew

How to Recursively Bash convert all your HTML to Markdown files with Pandoc

You can recursively convert all your HTML files to Mardown format in Bash, by using Pandoc. find . \-name "*.ht*" | while read i; do pandoc -f html -t markdown "$i" -o "${i%.*}.md"; done

March 29, 2023 · 1 min · 34 words · Andrew

How to Check if a Volume is Mounted in Bash

If you need to check if a volume is mounted in a Bash script, then you can do the following. How to Check Mounted Volumes First we need to determine the command that will be able to check. This can be done with the /proc/mounts path. How to Check if a Volume is Mounted in Bash if grep -qs '/mnt/foo ' /proc/mounts; then echo "It's mounted." else echo "It's not mounted....

August 12, 2022 · 1 min · 136 words · Andrew

How to Determine if a Bash Variable is Empty

If you need to check if a bash variable is empty, or unset, then you can use the following code: if [ -z "${VAR}" ]; The above code will check if a variable called VAR is set, or empty. What does this mean? Unset means that the variable has not been set. Empty means that the variable is set with an empty value of "". What is the inverse of -z?...

August 11, 2022 · 2 min · 287 words · Andrew