Revision 349
Added by Aaron Marcuse-Kubitza almost 13 years ago
bin/in_place | ||
---|---|---|
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" |
|
0 | 14 |
Also available in: Unified diff
Added in_place to run a stream command on a file