test a script about mount points

Hi there,
I would like people to test a script on as many situations as possible so we can find out errors and lacks.
I wrote the script to help me work around mount points, especially when doing batch job on files (like backup) and to avoid duplicate operations through mount points.
For example, consider the following mount points :

/home/santiago/folder       ->  /var/www/folder
/home/santiago/folder1      ->  /var/www/otherfolder

And the following files :

/home/santiago/file
/home/santiago/folder/file
/home/santiago/folder1/touch
/home/santiago/test/file2

If I backup /home and /var, I would like to be able to know what are the mount points under /home because it's not necesary to backup them. The scripts does it like this :

$ qmtpt /home
/home/santiago/folder
/home/santiago/folder1

Then I might wonder if a specific path is under a mount point or not. The scripts does it like this :

$ qmtpt /home/santiago/folder/file > /dev/null; echo $?
1
$ qmtpt /home/santiago/test > /dev/null; echo $?
0

Now, here is the script. It is supposed to work with extremely unusual paths (with all the weird character you can imagine). If you care about trying it, please report me any bug or necessary improvement. By the way, if it works let me know as well!

Thanks in advance
Santiago

#!/bin/bash

# Syntax
syntax () {
cat << EOF
Usage: $(basename "$0") PATH
Display mount points under PATH to the  standard output and returns a value that
indicates if PATH is itself under a mount point. Return values are:
  0     PATH is NOT under a mount point
  1     PATH IS under a mount point
  2     invalid command line arguments
  3     PATH does NOT exist
  4     Cannot read from /etc/mtab
EOF
exit 0
}

# Error functions
error () {
    p=$(basename "$0")
    h='\nTry '\'$p' -h'\'' for more information.'
    case $1 in
        2) m='invalid option '$2$h; n=2;;
        3) m='option '$2' requires an argument'$h; n=2;;
        4) m='invalid command line arguments'$h; n=2;;
        5) m='missing arguments'$h; n=2;;
        6) m='too many arguments'$h; n=2;;
        7) m=$2': no such file or directory'; n=3;;
        8) m='Cannot read from '$2': file does NOT exist'; n=4;;
        9) m='Cannot read from '$2': file has NO read permission'; n=4;;
        *) m='unexpected error'; n=255;;
    esac
    echo -e "$p"': '"$m" 1>&2
    exit $n
}

# Read options one by one
while getopts ":h" flag; do
    case $flag in
        'h') syntax;;
        '?') error 2 $OPTARG;;
        ':') error 3 $OPTARG;;
        *)   error 4;;
    esac
done

# Read other arguments
[[ $# -lt $OPTIND ]] && error 5
[[ $# -gt $OPTIND ]] && error 6
path=${!#}
mtab='/etc/mtab'

# Check path
[[ -e $path ]] || error 7 $path
[[ -f $mtab ]] || error 8 $mtab
[[ -r $mtab ]] || error 9 $mtab

# Build mount points list
mtpt=$(awk '$3 == "none" { print $2 }' $mtab)
# Build absolute path
[[ ${path:0:1} != '/' ]] && path=$(pwd)'/'$path
# Remove trailing slash
[[ ${path:${#path}-1} = '/' ]] && path=${path:0:${#path}-1}
# Replace spaces and backslashes
path=${path//\\/\\\\134}
path=${path// /\\\\040}
# Escape dollars, asterisks, periods and brackets
path=${path//$/\\$}
path=${path//\*/\\*}
path=${path//\./\\.}
path=${path//[/\\[}
path=${path//]/\\]}
# Display mount points under path
echo "$mtpt" | grep -E '^'$path'(/|$)' | sed 's/\\040/ /g; s/\\134/\\/g'
# Check if path is under a mount point
for p in $(echo "$mtpt"); do
    echo "$path" | grep -E '^'$p'(/|$)' > /dev/null
    [[ $? -eq 0 ]] && exit 1
done
exit 0

You know, the -xdev command in find will tell find not to traverse file-system boundaries. You can also use -P to ensure symbolic links are never followed. Those tips might help those with more basic needs.

Thanks otheus!
This will be terribly helpfull. Actually I still need this function to use the mirror function in lftp. I need to exclude directories that are mount points like this:

path=/home/
lftp x.x.x.x -u user,password -e "mirror -R $(qmtpt "$path" | awk '{ ORS = " " } { print "-x", $0 }') $path $path; quit"