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?

2 Answers 2


tee is designed for this purpose. I wrote the script sc:

while [[ $x != "X" ]] ; do
        printf "? "
        read x
        echo "User wrote: $x"

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.


You can run the command under script, which will capture its entire output in the file typescript for you. See man script for other options


Use Ctrl/D to exit the capture session

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .