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 "pre-recorded" demonstration of an interactive program? The script program can help with all of these problems.
NOTE: Versions of script on UNIX systems withoutaren't as flexible as the version I'm explaining here. For instance, those versions won't let you use during the script.
To copy everything you do into a file, just type:
scriptScript 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
(To use a different filename, type its
on the command line, like
When you're done, type CTRL-d or
at a shell prompt.
The good part is that you can "play back" whatever happened bythe 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" like
^M (carriage return) and
^H (backspace) characters.
(A command like
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 like
the ones in articles