#!/bin/bash
#
# compute n factorial using recursive function 
# (an example of recursion and use of bash arithmetic)
#
# usage:  factorial n
#
function fac() {
	if [ $1 -le 1 ]
	then
		echo 1
	else
		nm1=$(($1 - 1))
		recur=$(( $(fac $nm1) ))
		echo $(( $1 * $recur ))
	fi
}


if [ -z "$1" ]
then
	echo usage is $(basename $0) num
	exit 1
fi
# really ought to check here for numeric input, not less than 0

fac $1
