I'm running a bash script expecting occasional user input to continue processing the script. Is it possible to redirect the script output to a file while keeping the terminal output and keeping the application interactive, i.e. responding to my key presses?
tee is designed for this purpose. I wrote the script
##!/bin/bash while [[ $x != "X" ]] ; do printf "? " read x echo "User wrote: $x" done
then ran it as follows:
$ ./sc | tee f ? The first line User wrote: The first line ? another line User wrote: another line ? X User wrote: X $ cat f ? User wrote: The first line ? User wrote: another line ? User wrote: X
Pretty rough and ready, but it shows how to
tee off to a file.