chiark / gitweb /
Release 1.2.8.1.
[misc] / create
1 #! /bin/sh
2
3 set -e
4 case "$#:$1" in
5   0:* | 1:-h | 1:--help)
6     echo "$0 FILE PROG ARGS"
7     echo "  Run PROG with ARGS, writing its stdout to FILE if it succeeds."
8     echo "  Clobbers FILE.new."
9     exit 0
10     ;;
11   1:*)
12     echo >&2 "$0 FILE PROG ARGS"
13     exit 1
14     ;;
15 esac
16 file=$1; shift
17 set +e; "$@" >"$file.new"; st=$?; set -e
18 if [ $st -eq 0 ]; then
19   mv "$file.new" "$file"
20 else
21   rm "$file.new"
22 fi
23 exit $st