#! /bin/sh # Example showing the use of temporary files, and automatic removal # with a trap handler prog=$(basename $0) TMPFILE=$(mktemp /tmp/${prog}.XXXXXX) \ || { echo Cannot make tempfile; exit 1; } trap "rm $TMPFILE; exit" HUP INT QUIT PIPE ALRM TERM echo Your file is $TMPFILE lastb root > $TMPFILE # Now process and sort TMPFILE in different ways, # then finally remove it