root/bin/in_place @ 2164
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 |
trap "rm -f $temp" EXIT |
10 |
|
11 |
"$@" <"$file" >"$temp" || exit |
12 |
diff "$file" "$temp" >/dev/null && exit # don't update file if no change |
13 |
mv "$temp" "$file" |