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.

2 comments

@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.

Via https://unix.stackexchange.com/a/61833/1920.

@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

29 Answered Questions

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

9 Answered Questions

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

  • 2011-06-26 05:49:21
  • user775187
  • 1127632 View
  • 1218 Score
  • 9 Answer
  • Tags:   bash shell

36 Answered Questions

[SOLVED] Check if a directory exists in a shell script

  • 2008-09-12 20:06:25
  • Grundlefleck
  • 2704755 View
  • 3549 Score
  • 36 Answer
  • Tags:   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

6 Answered Questions

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

8 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
  • 60644 View
  • 75 Score
  • 8 Answer
  • Tags:   bash logging shell

1 Answered Questions

0 Answered Questions

Trying to tee inside bash script works on RHEL 6.7 but not on RHEL 6.8

8 Answered Questions

[SOLVED] tee and exit status

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

Sponsored Content