#!/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. if test 1 -neq $# then echo "arguments: output_file" fi a=$(mktemp) cat > "$a" cat "$a" > "$1" rm "$a"