#!/bin/bash
#
# compute n factorial using recursive function, another way 
# (an example of recursion and use of bash arithmetic)
#
# (FIXME improve sometime to check for input an integer?)
#
function factorial() {
    n=$1
    if [ $n -le 1 ]
    then
        echo 1
    else
        echo $(( $n * $(factorial $((n-1))) ))
    fi
}


if [ -z "$1" ]
then
    echo usage `basename $0` n
    exit 1
fi

echo factorial of $1 is:
factorial $1
