#!/bin/ksh

# GetTempPathName.ksh
# Chieh Cheng
# 2003-11-14
# http://www.CynosureX.com/

# GNU General Public License (GPL), Version 2, June 1991

  scriptName=`basename "$0"`

  usage ()
  {
    echo "  Usage:   $scriptname \"prefix\" [\"suffix\"] [\"directory\"]"
  }

  if [ $# -lt 1 ] || [ $# -gt 3 ]
  then
    usage
  else
    prefix="$1"

    if [ $# -gt 1 ]
    then
      suffix="$2"
    else
      suffix=".tmp"
    fi

    if [ $# -eq 3 ]
    then
      directory="$3"
    else
      directory="/tmp"
    fi

    i=0
    pathName="${directory}/${prefix}${suffix}"
    while [ -a "$pathName" ]
    do
      ((i = i + 1))
      pathName="${directory}/${prefix}${i}${suffix}"
    done

    touch "${pathName}"
    echo "${pathName}"
  fi
