Created
April 14, 2012 16:28
-
-
Save heftig/2385599 to your computer and use it in GitHub Desktop.
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
device_from_filename() { | |
# canonicalize filename | |
local realpath="$(readlink -e "$1")" | |
[[ ! -e $realpath ]] && return 1 | |
# read /etc/mtab into associative array mtab | |
local -A mtab | |
local device mountpoint rest | |
while read device mountpoint rest; do | |
mtab[$mountpoint]="$device" | |
done </etc/mtab | |
# find mountpoint | |
while [[ -n $realpath && -z ${mtab[$realpath]} ]]; do | |
realpath="${realpath%/*}" | |
done | |
[[ -z $realpath ]] && realpath=/ | |
echo ${mtab[$realpath]} | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment