X-Git-Url: https://git.distorted.org.uk/~mdw/misc/blobdiff_plain/1dec4fa32a4a6c57ffb2c736c0c6b95b0519cb67..3770fe80fa49fe8ad6a3c3697b268a18b8c13eb1:/create diff --git a/create b/create new file mode 100755 index 0000000..ae68817 --- /dev/null +++ b/create @@ -0,0 +1,23 @@ +#! /bin/sh + +set -e +case "$#:$1" in + 0:* | 1:-h | 1:--help) + echo "$0 FILE PROG ARGS" + echo " Run PROG with ARGS, writing its stdout to FILE if it succeeds." + echo " Clobbers FILE.new." + exit 0 + ;; + 1:*) + echo >&2 "$0 FILE PROG ARGS" + exit 1 + ;; +esac +file=$1; shift +set +e; "$@" >"$file.new"; st=$?; set -e +if [ $st -eq 0 ]; then + mv "$file.new" "$file" +else + rm "$file.new" +fi +exit $st