From 1c7cf90afae80918b82d823af59484f84391814f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 24 May 2017 15:57:34 +1200 Subject: Add dam(1df) --- bin/dam.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bin/dam.sh (limited to 'bin') diff --git a/bin/dam.sh b/bin/dam.sh new file mode 100644 index 00000000..03424515 --- /dev/null +++ b/bin/dam.sh @@ -0,0 +1,25 @@ +# Store up all input before emitting it unchanged as output +self=dam + +# Create a temporary directory with name in $td, and handle POSIX-ish traps to +# remove it when the script exits. +td= +cleanup() { + [ -n "$td" ] && rm -fr -- "$td" + if [ "$1" != EXIT ] ; then + trap - "$1" + kill "-$1" "$$" + fi +} +for sig in EXIT HUP INT TERM ; do + # shellcheck disable=SC2064 + trap "cleanup $sig" "$sig" +done +td=$(mktd "$self") || exit + +# We'll operate on stdin in the temp directory; write the script's stdin to it +# with cat(1) +cat -- "${@:-}" >"$td"/stdin + +# Only when that write is finished do we finally spit it all back out again +cat -- "$td"/stdin -- cgit v1.2.3