CS 1500
Making a Script


Once you are satisfied that your program is complete and runs correctly, you will make a script (record) of running your program. You will turn in the script (in a separate file) along with your program source code.

WARNING: Do not name you script the name of any existing file, especially your source code, because it will overwrite your file and your code will be gone for good.

Suppose that your program is called hello.cpp. In the terminal, make sure you are in the directory with you program:

mmartin@soleil:(~/1500) script hello.script
Script started, file is hello.script
mmartin@soleil:(~/1500) g++ hello.cpp
mmartin@soleil:(~/1500) a.out
Hello World!
mmartin@soleil:(~/1500) exitScript done, file is hello.script

Here's an explanation of what you just did: The "script" command turns on a program that makes a record of whatever appears on the screen. The command you entered was "script hello.script" so the record the script program makes will be a file called hello.script.

Enter "a.out" and see your "Hello World!" message written to the screen again. Now enter "exit" to turn off the scripting program. From the time you entered "script hello.script" to the time you entered "exit", all things that were written on the screen were also recorded in the file called hello.script.

Enter clear to clear the screen. Now enter "cat hello.script". This causes the computer to type the contents of the script file you made. It should look something like this:
mmartin@soleil:(~/1500) cat hello.script 
Script started on Tue Jan 29 18:52:53 2008
mmartin@soleil:(~/1500) g++ hello.cpp
mmartin@soleil:(~/1500) a.out
Hello World!
mmartin@soleil:(~/1500) exit
script done on Tue Jan 29 18:53:51 2008

Note that the script file (named hello.script) starts and ends with "timestamps" that tell when the script was started, and when it was completed. In between it reproduces what you typed.

Now enter "pico hello.script" so you can look at the script file with the PICO editor. You see your script. You also see "weird" characters in the script like ^M at the end of each line, and maybe some other things. These characters are an undesirable side-effect of the way the scripting program interacts with special characters that handle the terminal display. The weird characters are sometimes visible, and sometimes not, depending on just how you try to display your script file. The characters were not visible when you displayed hello.script with "cat," but they were visible when you used PICO. Do a ^x command (hold down the "ctrl" key and press "x") to exit PICO.

When you turn in a real programming assignment, you will be sending me the source code, plus a script similar to the one you just made. The script will be a record that will show me that you did the right kind of testing of your program.

I require you to run your script through a filter before you send it to me. It's a way to get rid of most of the weird characters, so the script will be more readable. It is easy to do, no matter how big the script is.

Here's how: Enter "cat hello.script | col -b > temp". This command pipes the script file to the input of the command "col -b > temp", which filters out some of the weird characters and writes the output to a file named temp. Now the temp file is the filtered version of the script. Enter "mv temp hello.script" to replace the script file with the new filtered version. Now enter "pico hello.script" again. See how the file has been cleaned up? Good. Exit PICO again using a ^x command. In summary:

mmartin@soleil:(~/1500) cat hello.script | col -b > temp
mmartin@soleil:(~/1500) mv temp hello.script
mmartin@soleil:(~/1500) pico hello.script