root/bin/in_place @ 7673
1 | 349 | aaronmk | #!/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 | 3755 | aaronmk | onExit () { rm -f "$temp"; } |
10 | trap onExit EXIT
|
||
11 | 349 | aaronmk | |
12 | 3754 | aaronmk | "$@" <"$file" >"$temp" || exit # don't update file on error |
13 | 349 | aaronmk | diff "$file" "$temp" >/dev/null && exit # don't update file if no change |
14 | mv "$temp" "$file" |