Commit 8cbb37c0 authored by nimrod's avatar nimrod
Browse files

Add dt (delayed tee), like tee but can output to the file that's being read...

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).
parent f45ac64f
Loading
Loading
Loading
Loading

Documents/bin/dt

0 → 100755
+12 −0
Original line number Diff line number Diff line
#!/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"