Are tee and script essentially equivalent?

限于喜欢 提交于 2019-12-04 13:58:05
blueyed

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!