You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
444 B
22 lines
444 B
#! /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
|