Project

General

Profile

1 8706 aaronmk
#!/bin/sh -e
2 349 aaronmk
# Runs a stream command on a file
3
# Usage: self file command
4
5
file="$1"
6
shift
7
8
temp="$(tempfile)"
9 3755 aaronmk
onExit () { rm -f "$temp"; }
10
trap onExit EXIT
11 349 aaronmk
12 8706 aaronmk
"$@" <"$file" >"$temp" # exits on error so file not updated
13 349 aaronmk
diff "$file" "$temp" >/dev/null && exit # don't update file if no change
14
mv "$temp" "$file"