How to check if filepath is mounted in OS X using bash?

This is what I use in my shell scripts on OS X 10.7.5

df | awk '{print $6}' | grep -Ex "/Volumes/myvolume"

For OS X 10.10 Yosemite I have to change to:

df | awk '{print $9}' | grep -Ex "/Volumes/myvolume"

While @hd1's answer gives you whether the file exists, it does not necessary mean that the directory is mounted or not. It is possible that the file happen to exist if you use this script for different machines or use different mount points. I would suggest this

LOCALMOUNTPOINT="/folder/share"

if mount | grep "on $LOCALMOUNTPOINT" > /dev/null; then
    echo "mounted"
else
    echo "not mounted"
fi

Note that I include "on" in grep statement based on what mount command outputs in my machine. You said you use MacOS so it should work, but depending on what mount command outputs, you may need to modify the code above.

Tags:

Macos

Bash