1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env bash outfile=$1 tmpfile="$(dirname "$outfile")/.tmp${outfile##*/}" cat > "$tmpfile" || exit $? if cmp -s "$tmpfile" "$outfile"; then rm -f "$tmpfile" || : else mv -f "$tmpfile" "$outfile" fi