Skip to content

Instantly share code, notes, and snippets.

@davidraedev
Created June 24, 2017 10:45
Show Gist options
  • Save davidraedev/a627a9cde6be2b170a2222e15c19c7b1 to your computer and use it in GitHub Desktop.
Save davidraedev/a627a9cde6be2b170a2222e15c19c7b1 to your computer and use it in GitHub Desktop.
mountpoint command for OSX
# OSX doesn't have a mountpoint command, or concise way to get that info
# this is a replacement for the mountpoint command, with the exception that it returns 2 instead of 1 for no argument
function mountpoint() {
# require a path
if [[ -z "$1" ]]; then
echo 'mountpoint requires a path as an argument';
echo 'ex. `mountpoint /mnt/some_disk`';
return 2;
fi;
# drop the trailing slash (unless it is root path)
check_path="$(realpath "$1")";
# loop through `mount` output and compare to each mountpoint
while read -r line; do
mount_path="$(echo "$line" | sed -n -e 's/\(.*on \)\(.*\)\( (.*\)/\2/p')";
if [ "$mount_path" = "$check_path" ]; then
echo "$check_path"' is mountpoint';
return 0;
fi;
done <<< "$(mount)";
echo "$check_path"' is not a mountpoint';
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment