Source

Centurion / Scripts / dismount

#!/bin/bash
# unmount USB drives

target=$(awk '/media\/[\^A-Z]/ {print $3}' <(mount))

if [[ -n "$target" ]]; then
    udiskie-umount -s "$target" &>/dev/null
    if [[ $? = 0 ]]; then
        printf "%s\n" "${target##*/} unmounted…"
    else
        printf "%s\n" "Unmounting failed."
    fi
else
    printf "%s\n" "No drive mounted…"
fi