aboutsummaryrefslogtreecommitdiff
path: root/scripts/update_out
blob: d3950cf601a0a289e8e22c0b86df073bb1b78403 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /bin/bash
# Run given command application and update the contents of a given file.
# Will not change the file if its contents has not changed.
[[ $# -gt 1 ]] || { echo "Usage: ${0##*/} FILE COMMAND" >&2; exit 1; }
set -u
declare -r outfile="$1"
shift
if [[ ! -f $outfile ]]; then
	$@ >$outfile
	exit
fi

declare -r newout=${outfile}.new
$@ >$newout
rc=$?
if cmp -s $newout $outfile; then
	rm $newout
else
	mv -f $newout $outfile
fi
exit $rc