SESSION 5 	MODIFYING AND EXECUTING PREVIOUS COMMANDS IN UNIX

1. ! and ^

The character keys ! and ^ can be used to repeat and/or modify commands
that you have typed in previously.

COMMAND                               ACTION

 !!			repeats last command

 !less			repeats last command beginning with `less'

 !w			repeats last command beginning with `w'

 !event_number		repeats the command with the given event_number

			e.g. type:         who am i
                             type:         less readme0
                             type:         !w
			     result:    who am i
                             type:         !less
			     result:    less readme0
			     type:         !event_number  (choose a number) 
			     result:    command with given event_number 
			                is repeated)


 ^string1^string2	substitutes `string1' for `string2' in the previous 
			command line

 !event_number string	appends ` string' to the command with the given 
			event_number

 !cat string		appends ` string' to the last command beginning with 
			`cat'

			e.g. type:         cat datfile birthday
			     type:         ^datfile^datefile
			     result:    cat datefile birthday
			     type:         !cat >date_birth
			     result:    cat datefile birthday > date_birth


 !!text			appends `text' to end of previous command line

			e.g. suppose you want to read the file `modify5'
			but omit the `5' by mistake:

			     type:         less modify
			     type:         !!5
			     result:    less modify5


 ^ls^less		changes previous command

		   e.g. if you wish to check whether the file `notepad6' 
			exists in the directory `ph354qu' and if so, 
			examine the contents of this file,

			     type:         ls notepad6
			     type:	   ^ls^less
			     result:    less notepad6


 !event_number:p	displays the command with given event_number but
			does not execute it

 !cat:p			displays the last command (beginning with `cat') but
			does not execute it

 ^cat^less:p		substitutes `cat' for `less' in the last command but
			does not execute it

 !!			now executes the changes you have made

 !c:s/cat/less		achieves all of the above 3 commands



2.            USING THE ARROW KEYS TO MODIFY THE COMMAND LINE

Successive presses of the arrow up key will display previous command lines.
To modify a previous command, use this key to locate the required command.
Then use the left and right arrow keys to move around the line. 

3. Exercises:

	a) Locate the file `readme0' by typing:  `ls readme0'.  Now use 
	the ^ key to read the contents of this file.
	b) Using the ! key, repeat the last command beginning with `ls'
	c) Using the ! key, type in ONE command which will enable you to 
	READ the contents of `readme0'.
	d) Bring up a list of your last 20 commands by typing ! followed 
	by Return. Now activate your last `ls' command by referring to its 
	event number.
	e) Press the up arrow key a few times to display a listing of your
	previous commands.

	 
END OF SESSION 5					file: modify5
