home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 51.4 Who's On? Chapter 51
Miscellaneous Useful Programs and Curiosities
Next: 51.6 Cleaning script Files

51.5 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 "pre-recorded" demonstration of an interactive program? The script program can help with all of these problems.

NOTE: Versions of script on UNIX systems without pty s (41.8 ) aren't as flexible as the version I'm explaining here. For instance, those versions won't let you use job control (12.1 ) 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 (1.21 ) on the command line, like script scriptfile .) When you're done, type CTRL-d or exit (38.4 ) at a shell prompt.

One thing that surprises people is that everything will be copied into the script file. That includes escape sequences (5.8 ) that programs send to your terminal. This is both good and bad.

The good part is that you can "play back" whatever happened by cat ting (25.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" like ^M (carriage return) and ^H (backspace) characters. (A command like cat -v or od -c (25.7 ) 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 35.11 , 43.18 , and 51.6 .

- JP

Previous: 51.4 Who's On? UNIX Power Tools Next: 51.6 Cleaning script Files
51.4 Who's On? Book Index 51.6 Cleaning script Files

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System