5 files changed, 48 insertions, 0 deletions
@@ -67,6 +67,9 @@ bin/motd
@@ -138,6 +138,7 @@ BINS = bin/ap \
+ bin/oii \
@@ -203,6 +204,7 @@ BINS = bin/ap \
BINS_M4 = bin/chn.m4 \
+ bin/oii.m4 \
@@ -212,6 +214,7 @@ BINS_M4 = bin/chn.m4 \
BINS_SH = bin/chn.sh \
+ bin/oii.sh \
@@ -277,6 +280,7 @@ clean distclean:
bin/chn.sh: bin/chn.m4 include/mktd.m4
bin/edda.sh: bin/edda.m4 include/mktd.m4
+bin/oii.sh: bin/oii.m4 include/mktd.m4
bin/pst.sh: bin/pst.m4 include/mktd.m4
bin/rndl.sh: bin/rndl.m4 include/mktd.m4
bin/swr.sh: bin/swr.m4 include/mktd.m4
diff --git a/README.markdown b/README.markdown
index bd4d482a..c99dcf6d 100644
@@ -499,6 +499,7 @@ Installed by the `install-bin` target:
* `motd(1df)` shows the system MOTD.
* `mw(1df)` prints alphabetic space-delimited words from the input one per
+* `oii(1df)` runs a command on input only if there is any.
* `onl(1df)` crunches input down to one printable line.
* `osc(1df)` implements a `netcat(1)`-like wrapper for `openssl(1)`'s
diff --git a/bin/oii.mi5 b/bin/oii.mi5
new file mode 100644
@@ -0,0 +1,19 @@
+# Only run a command on input if there was at least one byte
+# Need at least a command name
+if [ "$#" -eq 0 ] ; then
+ printf >&2 '%s: Need a command\n' "$self"
+ exit 2
+# There is probably a way better way to do this than writing the whole file to
+# disk and then reading it off again, but until I think of something better,
+# this works and is byte-safe.
+cat - > "$td"/in
+[ -s "$td"/in ] || exit
+"$@" < "$td"/in
diff --git a/man/man1/oii.1df b/man/man1/oii.1df
new file mode 100644
@@ -0,0 +1,21 @@
+.TH OII 1df "June 2017" "Manual page for oii"
+\- run a command on input only if there's at least one byte of input
+CMD [ARGS ...] < file
+CMD [ARGS ...]
+Run the given program passing in stdin but only if at least one byte of input
+is actually received, rather like the -E switch to mail(1) behaves on
+bsd-mailx. If no input is received, exit silently with an error status.
+It's slow, and doesn't work as a pipe. The entire input is written to disk and
+then tested for filesize before being re-emitted. There's almost certainly a
+more efficient way to do this while still remaining byte-safe.
+Tom Ryder <email@example.com>