Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71fe2cc7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "A script to update the file contents with the command output."

parents 25f15a18 82b6e848
Loading
Loading
Loading
Loading

scripts/update_out

0 → 100755
+21 −0
Original line number Diff line number Diff line
#! /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