#!/usr/bin/sh
if [ "`uname`" = "Linux" ]; then enable -n echo; fi
##*************************************
##
## E.S.O. - VLT project
##
## "@(#) $Id: tooOverwrite,v 1.34 2000/10/31 12:56:42 vltsccm Exp $"
##
## tooOverwrite"
## 
## who      when     what
##-------- -------- ------------------
##mchiesa 02/21/95 created for cmm
##
 #this is a Bourne Shell script (sh): therefore the first char != #
 # mchiesa 10.08.94


# tooOverwrite: copy stdin to stdout after EOF
# The UNIX Programming Environment, Brian W. Kernighan & Rob Pike
#    Prentice-Hall, Englewood Cliffs 1984, page 154f

opath=$PATH
#PATH=/bin:/usr/bin
PATH=/bin:/usr/bin:~/bin

case $# in
0|1)	echo $0' (Usage): tooOverwrite file cmd [args]' 1>&2; exit 2
esac

file=$1; shift
new=/tmp/overwr1.$$; old=/tmp/overwr2.$$
trap 'rm -f $new $old; exit 1' 1 2 15 # clean up files

if PATH=$opath "$@" >$new
then 
	cp $file $old	#save original file
	trap '' 1 2 15 	#we are committed; ignore signals
	cp $new $file
else
	echo "tooOverwrite: $1 failed, $file unchanged" 1>&2
	exit 1
fi
rm -f $new $old
