Created
June 24, 2017 10:45
-
-
Save davidraedev/a627a9cde6be2b170a2222e15c19c7b1 to your computer and use it in GitHub Desktop.
mountpoint command for OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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