Monitoring a file - Basic Bash Question

This is not homework I am new to UNIX and want to try this Monitoring a file demo
If this is the wrong forum please move it - im new to the forums

$1 = the file to be monitored
$2 = the time for the file to sleep

If the file gets changed (using -nt) it will send my username mail saying its changed it. The problem im having is it goes into an endless loop, im just learning the while loop so im guessing its that. Also I dont understand the whole mail code - how do I input subject and stuff.

#!/bin/bash
if [ $# -eq 0 ] ; then
    echo "enter <file> <time>"
exit 1
fi

if [ ! -e $1 ] ; then
    echo " please enter an existing file"
exit 2
fi

if [ "$2" = "" ] ; then
    echo " no argument 2"
exit 3
fi

if [ $2 -lt 10 ] ; then 
    echo " please enter a number higher than 10"
exit 4
fi

while [ $2 -ge 10 ] ; do
if [ $1 -nt ] ; then
    sleep $2
    mail $LOGNAME
else
    echo "file unchanged"
fi
done
exit 0

There are a couple of things wrong with your script. You never decrement the the sleep interval and so never exit the while loop. You also were incorrectly testing the file for changes. See how I have done it below.

#!/bin/bash

if [[ $# != 2 ]]; then
   echo "enter <file> <time>"
   exit 1
fi

if [[ ! -e $1 ]]; then
   echo "please enter an existing file"
   exit 2
fi

if [[ $2 < 10 ]]; then
   echo "please enter a number higher than 10"
   exit 4
fi

TFILE=/tmp/touchme.$$
touch $TFILE

i=$2
while (( i >= 10 )) ; do
    if [[ $1 -nt $TFILE ]]; then
        echo "file changed"
    else
        echo "file unchanged"
    fi
    sleep $i
    (( --i ))
done

rm $TFILE

exit  0

Finally you need to figure out what you information you want to email to yourself. mail $LOGNAME
does not mail anything.

Thanks man it works!