#!/bin/bash -e
# modify
# this no longer preserves the original files, and it does not preserve the inode numbers of the files

n=0
while [ "$1" != : -a $# -gt 0 ]
do
        FILE[$n]=$1
        n=$(($n + 1))
        shift
done
if [ "$1" != : ]
then
        echo usage: `basename $0` file ... : command >&2
        exit 1
fi
shift

for F in "${FILE[@]}"
do
	TMP_NAME="`dirname "$F"`/.`basename "$F"`.modify-$$"
	"$@" < "$F" > "$TMP_NAME"
	chmod --reference="$F" "$TMP_NAME"
	chown --reference="$F" "$TMP_NAME"
	rm -f "$F"
	mv "$TMP_NAME" "$F"
done
