CSCI 330 Fall 2000 - History - 50 Points
Due Monday, 6 November 2000, Close of CSL lab

Due in the drop box by the opening of the CSL lab, Tuesday
In other words, you better get it in the night before

When the question asks you to display something, that means to use echo to display it on the screen.

Because history has to be run at the terminal prompt, it is impractical to create a script or text file to test run them. You will have to work at the prompt and write down the answers you come up with.

For this assignment, you must perform the 4 numbered steps to prepare your login session for answering the problems. When the 4 steps are complete, you will be able to work on the problems labeled with letters. You are to figure out how to do each problem. When you have solved that problem, record it on a sheet of paper. It is this sheet of paper that you will be handing in.

1. Read up on the history command and make sure you know how the reverse history listing and un-numbered history listing work.

2. Edit the .history file in your home directory so that the first 6 lines contain the following 6 lines of commands.

echo First Second Third Fourth Fifth Sixth Seventh Eighth
~berezin/data/showme  AAA BBB  CCC   DDD  AAA  BBB  CCC   DDD   EEE
echo   1111 2222 1111 222 1111 2222 1111 222 1111 2222
echo hello goodbye  here  there where goodbye hello
echo /home/max/berezin/prog1.c
echo this list; ls -l
3. At the prompt, run the commands
% unset savehist
% login

4. Once you login again, use the history mechanism to perform the following exercises. Record your solution for each on a sheet of paper. On the lines where you refer to the previous line using one of the immediate meta-characters, you may have to re-run the line you are refering to if your first try at a solution does not work.

If your history line count gets to fifty, repeat step 3 and run the commands from problems a and b. to refresh the history list and reset the line counter. Note on your assignment that this was done.

When the problem refers to an history argument count, count the first string or token on the command line (usually the command) as argument 0. All following tokens are numbered from there.

a. Set your prompt to list the history line number and a > sign

b. Set the history variable to 50.

c. Display the contents of the history and prompt variables

d. List the current lines in the history list in reverse order

e. List the current lines in the history list without line numbers

f. List the current lines in the history list without line numbers and in reverse order

g. List the last six lines in the history list.

h. List the last six lines in the history list in reverse order.

i. Recall and run the first command line in the history list.

j. Recall and run the command line you just ran. Do not use the line number

k. Use the various features of history mechanism to copy the contents of line 4 of the history list to the current line without running it.

l. Now run the command line you just copied. Use immediate recall.

m. Recall and run the last set command you ran. Don't use the line number to recall it.

n. Recall and run the last command line that contained the word Six in it.

o. Display (use echo) the 1st argument of the 1st line and the last argument of the 1st line. Use the symbolic meta-characters for the first and last arguments.

p. Display (use echo) the 2nd through the 5th arguments of line 4.

q. Display all arguments from the 3rd to the last argument of line 1.

r. Recall and run line 2 with only its 1st two arguments. Do not specify each argument separately, treat as a range. You are recalling the command and the 1st two arguments on the command line.

s. Display the 2nd through the 4th arguments of line 6.

t. What actually happened when you did problem s?.

u. Re-run line 4 after changing all occurrences of the string goodbye to the string sequence abcd and wyxz

v. Re-run line 4 after changing all occurrences of the string goodbye to the string sequence abcd & wyxz

Enter the following line on the command line.

eko hello Sam

w. Now, use history to replace the k with ch so that it correctly spells echo. Do not use the line number, but rather use immediate substitution mechanism.

x. Use the immediate substitution mechanism to replace the string Sam with the string Mary and Joe

y. Use the immediate substitution mechanism to replace the string Mary with the string Mary and Sam but don't use the word Mary in the replacement side of the substitution sequence. Use the recall mechanism to insert the search pattern in the replacement side.

z. Use the immediate substitution mechanism and edit the previous line to replace the string Joe with the string Carl & Alice. You must get the & into the line. You will probably have to use a combination of quotes and \ (back qoute) to accomplish this.

aa. Fetch the command from line 2 (remember how history numbers the string sequence) and add the two words hello and George and the 4th argument from the 1st line and the 5th argument from the 2nd line in the history list.

ab. Recall and run line 3 after changing the 1st occurrence of the digit 1 to a 7 - By digit I mean a single character of numeric value

ac. Recall and run line 3 after changing the 1st occurrence of the number 1111 to the single digit 7 - By number I mean a single or multi-character string that represents a numeric value

ad. Recall and run line 3 after changing the all occurrences of the number 2222 to 7777

ae. Re-run line 3 after trying to change the each and every occurrences of the digit 2 to a 7.
Note: this can be done. The history mechanism tends to act on each argument (string) on the line, not on individual characters. But it (history mech.) also has a repeat symbol

af. Display just the path used in the first argument of the 5th line.

ag. Display the path and program name but not the extension of the 1st argument of the 5th line.

ah. Display just the program name in the first argument of the 5th line. Do not show path or extension.