37.7. Copy What You Do with script
Are you typing a complicated set of commands that you need to show someone else or keep "on file" for documentation? Are you debugging a program that goes wrong somewhere -- but the error message flashes by so fast that you can't see it? Do you want to show a "prerecorded" demonstration of an interactive program? The script program can help with all of these problems.
NOTE: Versions of script on Unix systems without ptys aren't as flexible as the version I'm explaining here. For instance, those versions won't let you use job control (Section 23.3) during the script.
To copy everything you do into a file, just type:
% script Script started, file is typescript %
Now you can type any Unix command that you'd use at a shell prompt. Everything you do is copied into a file named typescript in the current directory. (To use a different filename, type its pathname (Section 1.16) on the command line, like script scriptfile.) When you're done, type CTRL-d or exit (Section 24.4) at a shell prompt.
The good part is that you can "play back" whatever happened by catting (Section 12.2) the script to your screen. When things get boring, you can run an interactive program like vi inside the script -- then quit the script and play it back with cat typescript. The cursor will fly across the screen and your file will be re-edited before your eyes. (This is easier to see if the terminal is set to a slow data rate.)
The bad part is that errors you correct and other terminal-control sequences will be in the file, too. If you edit or print the script file, it may be full of "junk" such as ^M (carriage return) and ^H (backspace) characters. (A command like cat -v or od -c (Section 12.4) will show you these characters.) If the file has just a few of these characters, you can clean it up by hand with your text editor's global substitution commands. You can also automate your "script cleaning" with techniques such as the ones in Section 21.11 and Section 37.8.
If you're using xterm, it may have a built-in logger. Check its menus (Section 5.17).
Copyright © 2003 O'Reilly & Associates. All rights reserved.