Sample of What You'll See Using the Unix script Command

script is a standard Unix command that records a script of your interaction with the Unix system. Once it's started, it works "in the background", meaning that you continue to work normally, but the script session is dumping everything that shows up on your screen (more or less*) into some file. To start a script session, issue the command script to the Unix shell; then continue on working normally as long as you like. If you don't provide a file name to the script command, it places its output in a default file named typescript, but for CS125, I recommend you name your script file hwn.txt, where n is the number of the programming assignment you're doing.

Anyway, when you decide you don't need to record stuff anymore, exit from the scripting session by issuing the command exit to the Unix shell. Here's a picture and some further discussion:

Line [1]: The % is the standard Unix shell prompt, in response to which I have entered the Unix command script and told it (script) to place all its output in a file named test_script.txt  
Line [2]: This line is from the script program telling me that it has started and is recording everything.
Line [3]: This line starts with another standard Unix prompt (%), to which, in this example, I responded by entering the command ls. (When you use script to prepare a file to turn in for CS125, you won't be using ls, just cat and gcc; but Unix and the script command don't care what you do inside a script session.)
Line [4]: This is the output from the ls command.
Line [5]: This line starts with another Unix prompt, to which I reply exit, meaning "exit from the scripting session". Technically, exit exits the current shell, which you hope is actually a subshell (running script) of your login shell. If you forget where you are (you can be 20 shells deep as far as Linux is concerned; it doesn't care) and inadvertently exit from your login shell, you are logged off the system. What, you say? That's not very user-friendly? Welcome to the real world; Linux is not a toy.
Line [6]: Lines 6 and 7 are the response from script as it exits and stops the scripting session.
Line [8]: This is the standard Unix shell prompt, waiting for me to continue on, but from now on, nothing will be recorded anywhere (since I'm not in a script session anymore)

If I wanted to, at this point (line 8 and forever after) I could use an editor or other Unix tools to take a look at the output file of the script (which I put in test_script.txt, in the example above; but I could have named the output file anything I wanted or left it blank, in which case Unix would have assigned a default name of   typescript). In any event, what I would see would be a perfectly ordinary text file, containing, in this particular case, lines 2 through 7, above.

 
*
The reason for the "more or less" comment is that only characters that are input or output "normally" (i.e., a line at a time) are guaranteed to show up in the output of the script. Editors like pico, for example, do their I/O a little differently; they have to, since they use the whole screen not just a line at a time. I just ran an experiment and started pico inside a script. It looks like the script file contains a pretty nice capture of what my pico-screen looked like right at the point when I exited from pico, but there's no record of how it got to look that way (i.e., there's no real record of the keystrokes I typed into pico itself, unless they showed up visually in the final window). Running "more" from within a script session yielded strange results, however. But "normal", one line at a time, character-based input and output gets captured perfectly. Note that script captures all "normal" keystrokes, including the keys (like 'backspace' or 'delete') that you use to correct mistakes. So you'll usually see a few weird characters, like ^M and stuff like that in your script file. (You'd need to understand your keyboard map to know what these characters mean; but that's way beyond CS125.)


This page last changed 12 Oct 2003 by Dr. M.S. Jaffe