How to run a command only if a certain drive is mounted?

Using df and grep like that is terrible. Too many ways for that to fail.

Although the real problem is that you didn’t properly reference the variable. It should be "$mounted" in the if

Either way, try this:

if [[ -n $(findmnt /mountpoint) ]] ; then
	command_1
else
	command_2
fi
2 Likes