GetWhitespaceSafeMounts

7th July 2016 at 10:53am
Bash CodeSnippets
cat /proc/mounts \
  | cut -f 2 -d ' ' \
  | while read -r line ; do echo -e "${line}"; done
list_targets () {
    local device
    [[ -z "${1:-}" ]] || device=$(readlink -f "${1}")
    while IFS=" " read -r source target rest; do
        # Not doing grep because need exact match here.
        # Need echo -e to unescape source/target.
        if [[ -z "${device:-}" || "$(echo -e "${source}")" = "${device}" ]] ; then
            echo -e "${target}"
        fi
    done < /proc/mounts
}