#!/bin/sh # # # gettmpfile -- get one or more temporary files # cleanup() { if [ "$TMPFILES" != "" ]; then for i in $TMPFILES; do if [ -f $i ]; then LIST="$LIST $i" fi done if [ "$LIST" != "" ]; then rm $LIST fi fi } __gettmp() { let 'count = count + 1' tmpfile=$TMPDIR/$prefix-$now-$count TMPFILES="$TMPFILES $tmpfile" } program=`basename $0` trapsignals="0 1 2 3 15" TMPDIR=/tmp prefix=tmp ext= options=`getopt de:p:T: $*` || exit 1 set -- $options while true; do opt=$1 case $opt in -d) set -x shift ;; -e) ext=$2 shift 2 ;; -p) prefix=$2 shift 2 ;; -T) TMPDIR=$2 shift 2 ;; --) shift break ;; -*) echo $program: unknown option: $opt 1>&2 exit 1 ;; *) break ;; esac done # # Check parameters ... # if [ "$#" '!=' 0 ]; then echo usage: $program '[]' 1>&2 exit 1 fi # # ... capture signals, set some default values ... # trap 'cleanup; exit' $trapsignals now=`date +'%s'` pid=`printf '%05d' $PPID` count=0 # # ... and start. # __gettmp echo $tmpfile # # Create more temporary filenames as required. # while read line; do __gettmp echo $tmpfile done exit 0