summaryrefslogtreecommitdiff
path: root/write-ifchanged
blob: c65fa160075af3598ac6257669a9d2f44dbcf361 (plain)
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