The version of FreeBSD 8.0 that I am using is missing tee & tee -a (tee append)
You know tee as in write on screen & file:
date | tee thedate.txt
Which will run command date and show its output on the screen (stdout) and also write that same output to thedate.txt. tee and tea read in via STDIN supplied by the Pipe. Recall that Pipes connect the STDOUT of the left side (date) to the STDIN on the right side (tee). Pipes operate on the send STDOUT, not STDERR, so you might be missing some precious error output (error messages, debug messages, and help messages are sometimes output as STDERR with nix systems). To get STDERR into the TEE you have to do this little trick.
date 2>&1 | tee thedate.txt
Which says STDERR (2) output should also go to the address (&) of STDOUT (1).
The tee you are familiar can be run as tee filename or tee -a filename, where -a appends to an existing file where as regular tee (Without -a) writes to a new file (and if file exists it truncates,deletes, old contents)
Here are the two as two seperate bash functions. tee for regular tee. And tea for append tee.
unset tee; tee () { rm -f "$1"; cat - | while IFS= read -r line; do echo "$line"; echo "$line" >> "$1"; done; }; unset tea; tea () { cat - | while IFS= read -r line; do echo "$line"; echo "$line" >> "$1"; done; }; # tee - regular mode & tea - append mode
Enjoy
Use like:
date | tee thedate.txt
Which will show the date on the screen and save it to file. Repeating command will update the date string inside the file.
date | tea thedate.txt
Which will show the date on the screen and save it to file. Repeating command will append the new date string inside the file.