Kornshell function to keep revisions of a file

Sometimes while developing scripts you want to keep backups of certain files, but are worried that over time the old versions will fill the filesystem and need housekeeping.

The following function will allow you to keep only <n> versions of a file (the default is 5 backups) with older ones getting removed automatically. 

# Usage: FN_keep_revisions <filename> [<revisions>:5]

function FN_keep_revisions
{
   typeset FSP=${1}
  typeset -i GEN=${2:-5}
  typeset -i NEXT

  while [ "${GEN}" -gt 0 ] ; do
    NEXT=$((GEN-1))
    if [ "${GEN}" -eq 1 ] ; then
      mv -f ${FSP} ${FSP}.${GEN}
    else
      mv -f ${FSP}.${NEXT} ${FSP}.${GEN}
    fi
    GEN=${NEXT}
  done
 }