:
##########################################################################
# Title      :	T - generate temporary file name
# Author     :	Heiner Steven <heiner.steven@odn.de>
# Date       :	1995-05-11
# Requires   :	
# Category   :	System Utilities
# SCCS-Id.   :	@(#) T	1.4 09/01/04
##########################################################################
# Usage example:
#	$ diff sorted_file `T sort -u file1`
# Note
#    o	Newer shells (bash, ksh93, zsh) support process substitution
#	where the results of a command are written to a pseudo-file and
#	the name of the file can be used directly:
#	    $ diff sorted_file <(sort -u file1)
#
#	Print the file name:
#	    $ echo <(sort -u file1)
#	    /dev/fd/4
##########################################################################

PN=`basename "$0"`			# program name
VER='1.4'

Tmp=${TMPDIR:-/tmp}/T$$			# Temporary file
SleepTime=10				# Time to wait before removing $Tmp

usage () {
    echo >&2 "$PN - generate temporary file names, $VER (stv '95)
usage: $PN command [args]

The given command is executed with the given arguments, and the
output is redirected to a file. The filename is then printed to
stdout. The file is removed automatically $SleepTime seconds
after the command ended.

Example:
	diff \`$PN ls oldfiles\` \`$PN ls newfiles\`"
    exit 1
}

while [ $# -gt 0 ]
do
    case "$1" in
	--)	shift; break;;
	-h)	usage;;
	-*)	usage;;
	*)	break;;			# command
    esac
    shift
done

[ $# -lt 1 ] && usage

trap '(sleep $SleepTime; rm -f "$Tmp" > /dev/null 2>&1)&' 0
trap "exit 2" 1 2 3 

exec 3>&1 > "$Tmp" 2>&1
eval "$@"
echo "$Tmp" >&3
exec 3>&-				# close old stdout
