Project

General

Profile

« Previous | Next » 

Revision 349

Added in_place to run a stream command on a file

View differences:

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