Skip to content

Instantly share code, notes, and snippets.

@qizhihere
Created July 3, 2015 11:34
Show Gist options
  • Save qizhihere/3de7885d850535a9182b to your computer and use it in GitHub Desktop.
Save qizhihere/3de7885d850535a9182b to your computer and use it in GitHub Desktop.
check if the specific device has been mounted
is_mounted () {
if [ $# -eq 1 ]; then
if [ ! -b "$1" ]; then
echo "error: invalid device:$1"
return 1
elif df | awk '{print $1}' | grep "$1" &>/dev/null; then
return 0
else
return 1
fi
elif [ $# -eq 2 ]; then
if [ ! -b "$1" ]; then
echo "error: invalid device:$1"
return 1
elif df | awk '{print $1,$6}' | grep "^$1 $2$" &>/dev/null; then
return 0
else
return 1
fi
else
echo "error: invalid arguments"
echo "Usage: is_mounted /dev/sdxN [directory]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment