aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-20 16:47:37 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-20 16:47:37 +1200
commitfa2f423345776d8a99dae604f89e5b0ba76ceabb (patch)
tree8e1d83f9ea24ce519246b52921cc66350e39bdd0 /bin
parentRemove readv() and readz() (diff)
downloaddotfiles-fa2f423345776d8a99dae604f89e5b0ba76ceabb.tar.gz
dotfiles-fa2f423345776d8a99dae604f89e5b0ba76ceabb.zip
Port fnl() to POSIX sh script fnl(1)
No real compelling reason to make it a shell function in the first place.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fnl21
1 files changed, 21 insertions, 0 deletions
diff --git a/bin/fnl b/bin/fnl
new file mode 100755
index 00000000..d27d1f90
--- /dev/null
+++ b/bin/fnl
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Run a command and save its output and error to temporary files
+
+# Check we have at least one argument
+if [ "$#" -eq 0 ] ; then
+ printf >&2 'fnl: Command needed\n'
+ return 2
+fi
+
+# Create a temporary directory; note that we *don't* clean it up on exit
+dir=$(mktd fnl) || exit
+
+# Run the command; keep its exit status
+"$@" >"$dir"/stdout 2>"$dir"/stderr
+ret=$?
+
+# Run wc(1) on each of the files
+wc -- "$dir"/*
+
+# Exit with the wrapped command's exit status
+exit "$ret"