Issued on: Tuesday midnight, February 6, 2007.
Due by: Tuesday midnight, February 20, 2007.
For this assignment, a paper submission and an electronic submissions are required. The electronic submission consists of source programs (one for each of the following questions: 3, 6 and 7) and shell interpreter sessions produced with script command (one Questions 4).
These source programs can be sent by email to the instructor.
As usual, you need also an assignment ticket and an submission form, to be included in an envelope together with the paper submission.
The locker of CS211b is 99 at the groundfloor of Middlesex College.
Let us start by a review of the notions covered during the first two weeks. For each of the following 15 actions, please, give a shell command line executing it, and test it on one example. Then, record your test runs using the script command.
- (A) Give a single command which will change the current working directory to your home directory.
- (B) Give a single command which will list the contents of the directory /gaul.
- (C) Give a single command which will give your username.
- (D) Give two commands which will create a directory called temp in your home directory, and change the current working directory to be that directory. These commands should work no matter what your initial working directory is!
- (E) Give a single command which will display the contents of the file /etc/motd.
- (F) Give a single command which will display the contents of the file /etc/motd with each line numbered.
- (G) Give a single command which will calculate the addition 5 + 10 and display the answer.
- (H) Give a single command which will list all the files and directories in the current directory. Only the name of each file/directory should be displayed, and only one name may appear on each line.
- (I) Using one echo command, display the full path of your home directory.
- (J) If your current working directory is ~/temp/ (where ~ is your home directory), list 4 different ways of changing the current working directory to be your home directory without typing the full path name of your home directory.
- (K) If your current working directory is your home directory, give a single command to list all files ending in the extension .c, in your home directory and all subdirectories.
- (L) If you have a file called -i in your current working directory, give a single command to delete that file.
- (M) Give a single command that will list all files in the current working directory that start with a digit (0 to 9).
- (N) Give a single command that will list all files in the current working directory whose names are 1 character long (eg: "a", "1", etc...).
- (O) Give a single command which will change the permissions of a file called "blaah.txt" (located in your current working directory, and owned by you), so that every user on the system is able to read the file, but only you are able to change the file.
In this exercise, you make use of the commands tr and grep.
We assume that in our current directory we have a textfile Text which consists of words, separated by dots, blanks, commas and return characters. Each word is a sequence of lower case characters. No other characters are present in Text.
Write a sequence of shell commands (in tcsh, csh or bash) in order to perform the following actions.
- (A) Create a file dict consisting of the words occuring in Text and such that dict has exactly one word per line. A word may appear at several lines of the file dict.
- (B) Check whether Text contains repeated words.
- (C) Check whether Text contains words starting with a run of 3 consonants.
- (D) Check whether Text contains words with m as their only consonant.
- (E) Check whether Text contains words with a 3 letter palindrome as subword (such as in Toronto).
In this exercise, we continue our discovery of shell-scripts. Study the script unix.sh in the directory lecture-shellscripts containing the scripts used in this course.
Then, write a script containTheirNames.sh which lists all the files in the current directory that contain their names (without extension) as a subword. If you run the script containTheirNames.sh in the directory lecture-shellscripts this should list (at least) the following files:
arguments.sh   executables.sh   filepoke2.sh   filepoke2.sh   ls.sh   multiplicationtable.sh   removeEmptyFiles   touch.sh   unix.sh   usesemicolon.sh  
Use the man command to learn or review the commands ps and script.
Provide one-line Unix commands to solve each of the following tasks:
- (A) Show all processes owned by you on the system and put that list in a text file "proclist.txt".
- (B) Put into a file called "myprocs.txt" the text "Here is a list of my processes" followed by a list of only your processes taken from the file "proclist.txt" created above. Capture a session in which you run this command and show that the file "myprocs.txt" was created properly by displaying its content.
- (C) If the file "myprocs.txt" already existed, what changes (if any) would you need to make to your command work?
Sometimes it can be frustrating to figure out where you put files. In the following questions, you are trying to find a file or files.
Use man command to learn or review the command find. Then, answer the following questions.
- (A) Provide a one-line Unix command to find all of the files in or under your current working directory that are at least 100K in size.
- (B) Provide a one line Unix command that will go into and under your current working directory and will compress any file which has not been modified sometime in the past week.
Master Mind! Here's a very simplified version of this famous game. Player A chooses at random an integer x between 1 and 100. Player B gives successive values y1, y2, ...
- until a value yi becomes equal to x, in which case B is the winner,
- or until for two consecutive values yi and yj the distance between yj and x is larger than the distance between yi and x , in which case A is the winner.
Write a C program implementing this game such that a human Player B could play against the computer, Player A.
This program should allow Player B
- to play several games successively,
- to quit the program before completing a game,
- to obtain the scores (the number of games won by A and B) between two games.
Statistics!
Write a C program performing the following actions:
- Read floating point numbers from the user, in an interactive manner, until the user interrupts this process,
- Print the average value of these numbers, together with the largest one and the smallest one.