Project

General

Profile

1
#!/bin/sh -e
2
# Runs a stream command on a file
3
# Usage: self file command
4

    
5
file="$1"
6
shift
7

    
8
temp="$(tempfile)"
9
onExit () { rm -f "$temp"; }
10
trap onExit EXIT
11

    
12
"$@" <"$file" >"$temp" # exits on error so file not updated
13
diff "$file" "$temp" >/dev/null && exit # don't update file if no change
14
mv "$temp" "$file"
(32-32/81)