By Michael Le Barbier Grünewald

2015-02-19 08:20:04 8 Comments

In the context where I want to capture the stdout of a process in a file but still want to have this output displayed in the terminal I can choose between script and tee. In this context, are these tools essentially equivalent or is there a – possibly subtle – reason to prefer one over the other?

The programs script and tee are designed for different purposes:

  • script -- make typescript of terminal session
  • tee -- pipe fitting

Important differences between script and tee are:

  • script transmits the exit status of the process it supervises, while tee, being a filter, does not even know about it.
  • script captures stdin, stdout, stderr of the process it supervises while tee only catches the stream it filters.

None of these differences are relevant in the given context.


@blueyed 2016-09-01 10:55:57

I found script to be useful for making control sequences work when piping to tee:

script -q -c 'python -c "import pdb, sys; pdb.set_trace()"' /dev/null \
| tee -a /tmp/tmp.txt

With only the following, Ctrl-A would be displayed as ^A etc:

python -c "import pdb, sys; pdb.set_trace()" | tee -a /tmp/tmp.txt

This is a minimal example. I am using tee here to capture the output from a pytest test run, but sometimes there might be a debugger in there, and cursor keys etc should work then.


@Wolph 2015-02-19 08:50:55

They have a very different purpose and the usage is quite different as well.

  • Script is to record what you are doing in a shell session. Handy to show a professor what you did, to show co-workers how to do something, etc...

  • Tee is just an application to write to both your screen and a file. Very handy when installing something or running a command that generates a lot of output and wanting to see the output realtime while still saving it to disk.

A notable difference between the two is that you can use script to create an interactive shell to log everything (e.g. script commands.log zsh) including colors and such. Tee won't register as a tty so with that regard it's pretty different.

Related Questions

Sponsored Content

10 Answered Questions

[SOLVED] Check existence of input argument in a Bash shell script

  • 2011-06-26 05:49:21
  • user775187
  • 1268200 View
  • 1369 Score
  • 10 Answer
  • Tags:   bash shell

31 Answered Questions

[SOLVED] How do I prompt for Yes/No/Cancel input in a Linux shell script?

35 Answered Questions

[SOLVED] How can I check if a directory exists in a Bash shell script?

  • 2008-09-12 20:06:25
  • Grundlefleck
  • 2809518 View
  • 3748 Score
  • 35 Answer
  • Tags:   bash shell unix posix

16 Answered Questions

[SOLVED] How to use SSH to run a shell script on a remote machine?

13 Answered Questions

[SOLVED] YYYY-MM-DD format date in shell script

9 Answered Questions

[SOLVED] How do I get both STDOUT and STDERR to go to the terminal and a log file?

  • 2008-12-12 16:18:30
  • JPLemme
  • 70918 View
  • 99 Score
  • 9 Answer
  • Tags:   bash logging shell

7 Answered Questions

[SOLVED] How to replicate tee behavior in Python when using subprocess?

1 Answered Questions

8 Answered Questions

[SOLVED] tee and exit status

  • 2009-06-12 09:44:03
  • pachanga
  • 10606 View
  • 15 Score
  • 8 Answer
  • Tags:   unix shell tee

Sponsored Content