sponge as a shell script for non-interactive use, i.e., where we do not need to check the second file
#!/bin/sh
test $# = 1||exec echo usage: $0 file;
test -f $1||exec echo $1 does not exist;
test ! -f $1.tmp||exec echo $1.tmp exists;
cat > $1.tmp;
mv $1.tmp $1;