#!/bin/bash
-root=$1
if [[ -z $1 ]] ; then
echo "Usage: $0 <root>"
exit 1
fi
-mounts=$(mount | grep " on ${root%/}/" | awk '{print $3}' | tac)
+while [[ $# -gt 0 ]] ; do
+
+root=$1
+shift
+
+mounts=$(gawk -v p="${root%/}" '$2 ~ "^"p { print $2 }' /proc/mounts | tac)
if [[ -z ${mounts} ]] ; then
echo "No mounts found ..."
echo
mount
- exit 0
+ continue
fi
echo "Unmounting: "
printf "OK? [y/N] "
read v
[[ ${v} == "y" ]] && sudo umount -v ${mounts}
+
+done