Possible Duplicate:
How do I test if a variable is a number in bash?
I try writing the fibonacci sequence by shell scripting for example if user entered 5 after the script name in the command line the script needs to print out the 5 fibonacci numbers from the beginning which are:
0 1 1 2 3 
I have completed the script but I need to check the user input if it is positive number that I have a problem in this part. in the command line the user should call the script and then enter a positive number
./script number
and this is my code:
#!/bin/sh
[ $# -ne 1 ] && { echo "enter a number please" ; exit 1 ; } 
[ ! echo $1 | egrep -q '^[0-9]+$' &&  $1 -lt 0  ] && { echo "negative" ; exit 1 ; }
f0=0
f1=1
counter=2
if [ $1 -eq 0 ] ; then
echo -n "0"
elif [ $1 -ge 1 ] ; then
    echo -n "0 1" 
fi
    while [ $counter -le $1 ] && [ $1 -gt 1 ] ; do
        echo -n "$fn "      
        fn=`expr $f0 + $f1`
        f0=$f1
        f1=$fn
        counter=`expr $counter + 1`
    done 
echo ""
 
     
    