summaryrefslogtreecommitdiff
path: root/write-ifchanged
diff options
context:
space:
mode:
Diffstat (limited to 'write-ifchanged')
-rwxr-xr-xwrite-ifchanged11
1 files changed, 11 insertions, 0 deletions
diff --git a/write-ifchanged b/write-ifchanged
new file mode 100755
index 0000000..c65fa16
--- /dev/null
+++ b/write-ifchanged
@@ -0,0 +1,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