From 8cbb37c01510b70a52832399bb3171a15bfbd4d4 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Sun, 19 May 2019 15:59:46 +0300 Subject: [PATCH] Add dt (delayed tee), like tee but can output to the file that's being read from (for example sort foo.txt | dt foo.txt). --- Documents/bin/dt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 Documents/bin/dt diff --git a/Documents/bin/dt b/Documents/bin/dt new file mode 100755 index 0000000..a434aec --- /dev/null +++ b/Documents/bin/dt @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +[ "$#" -gt '0' ] || { echo "Output not specified." >> /dev/stderr; return 1; } +while [ "$#" -gt '1' ] +do + args="${args:-} $1" + shift +done +tempfile="$(mktemp -p .)" +# shellcheck disable=SC2086 +tee ${args:-} "$tempfile" && mv "$tempfile" "$1" -- GitLab