#!/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