#!/bin/sh # overwrite: copy standard input to output after EOF. # From ``The UNIX Programming Environment'' by Kernighan & Pike opath=$PATH PATH=/bin:/usr/bin case $# in 0|1) echo 'Usage: overwrite 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 # Collect input. then cp $file $old # Save original file. trap '' 1 2 15 # We are committed; ignore signals cp $new $file else echo "overwrite: $1 failed, $file unchanged." 1>&2 exit 1 fi rm -f $new $old