Project

General

Profile

1
#!/bin/sh
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" || exit # don't update file on error
13
diff "$file" "$temp" >/dev/null && exit # don't update file if no change
14
mv "$temp" "$file"
(21-21/54)