New scripts.
[misc] / create
diff --git a/create b/create
new file mode 100755 (executable)
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