: ########################################################################## # Shellscript: tmpname - print temporary file name # Author : Heiner Steven # Date : 1992-12-18 # Category : File Utilities # SCCS-Id. : @(#) tmpname 1.2 04/02/18 ########################################################################## # Description # - A name is unique for each terminal session # - The file will be written into the directory given by the TMPDIR # environment variable (default is /tmp) # - An argument will be used as part of the file name. This way, # multiple file names can be created (e.g. "tmpname 0", "tmpname 1"). ########################################################################## # Changes # 1993-02-10 stv create shorter file names ########################################################################## PN=`basename "$0"` # Program name VER='1.2' Usage () { echo >&2 "$PN - create temporary file name, $VER usage: $PN [-p prefix] [id] -t: file name prefix (default is \"t\") The temporary file name is unique for each terminal session (derived from the output of the command \"tty\"). Multiple temporary files for a given session can be created by specifying an \"id\" on the command line. This id will be appended to the base file name. The line rm \`tmpname\`* will remove all files created using \"tmpname 0\", \"tmpname 1\" etc." exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } set -- `getopt :hp: "$@" || exit 1` || Usage [ $# -lt 1 ] && Usage # "getopt" detected an error Prefix=t while [ $# -gt 0 ] do case "$1" in -p) Prefix=$2; shift;; --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done if [ $# -gt 0 ] then Id="$1" else Id= fi : ${TMPDIR:=/tmp} # Directory containing file TermName=`tty 2>&1 | sed -e 's:/dev/::' | sed -e 's:/::g'` echo "$TMPDIR/$Prefix${TermName}$Id"