#!/bin/sh -e # write to output file only after all data from standard input has been read. # allows to overwrite source files when using shell output redirection. # example: cat file | grep -v xyz | late-write file if test 1 -ne $# then echo "arguments: output_file" fi a="$(mktemp)" cat > "$a" cat "$a" > "$1" unlink "$a"