get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script?

I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1.

Here is a start but I have no clue how to continue:

#!/bin/sh

Thanks in advance...

## Set $n to the factorial number
## Use the first command-line argument if set, otherwise
## default to 5
n=${1:-5}

## Loop while $n is greater than 1
while [ $n -gt 1 ] 
do

  ## $f is the factorial in progress
  ## if not set, it is initialized with 1
  ## It should be set at the top of the script
  ## in case of existing value
  ##
  ## Multiple $f by $n
  f=$(( $n * ${f:-1} ))

  ## Decrement $n
  n=$(( $n - 1 ))
done

## Print the result
echo $f

Hi,

Thanks for this solution ...
Can you please put in with comments what does what?

Thanks,

thanks for the explanation cfajohnson