Download Here - Computer and Information Science
Transcript
96 V. MISCELLANEA present the text to be added is only the text in line 5. Here $2 is to be interpreted as the second argument of the shell command $ letter cmuser5 Charley, i.e., Charley, (including the comma). You may want to address this person as Charley: or as Professor Cmuser:; accordingly, you may want to type the command lines $ letter cmuser5 Charley: $ letter cmuser5 ’Professor Cmuser:’ In the last example, the quote character will be stripped by the shell program; i.e., you will properly obtain the line Professor Cmuser: rather than ’Professor Cmuser:’ Instead of single quotes, double quotes (shift–’) can also be used, i.e., the command line could have been typed as $ letter cmuser5 "Professor Cmuser:" In line 7, the output of the date command is placed into the file being edited after line 1. In this line, 1 is the line number of the file being edited, r means read into this file, the exclamation point ! indicated that what is going to be read is the output of a Unix command, and date is the Unix command in question. The output of date is the current date and time. Line 8 says that lines 1 and 2 have to be joined into a single line. In line 9, the letter a indicates that the text in the next few lines will have to be added; again, only one line, line 10 is added, since the single period in line 11 indicates the end of the lines to be added. In line 9, $ refers to the last line of the file being edited; that is the text in line 10 has to be added after the last line. In ed , as in vi command-line mode, $ refers to the last line of the file being edited. The backslash \ is the shell quote character; this means, that the dollar sign $ in line 9 is quoted as far as the shell is concerned; the shell strips the quote character \, and ed will receive only $a instead of the present form of line 9. If we had written $a for line 9, that is, if it had been written without the quote character, then the shell would have interpreted $a as indicating the value of a shell variable; if this variable is not defined (as is likely to be the case at present), this value will be the empty string, and ed would receive the empty string in line 9 instead of $a. Lines 12–14 add the content of lines 13–14 at the beginning of the file being edited (since these are written in separate lines, two separate lines will be added). The letter w instructs ed to write the result of the editing out to the file being edited (this works in much the same way as the command w works in vi in command-line mode). Finally, q in line 18 quits ed and, the end of the here document is marked in line 18. Line 19 is now a command to be interpreted by the shell; it will open up the file in vi for further editing. We already commented between the similarities of ed and vi. To mention further similarities, versions of the command a in lines 4, 9, and 12 in vi are somewhat analogous to pressing a in vi command mode, which causes a change to insert mode (see p. 13), and the period in lines 6, 11, and 15 is similar to pressing the escape key in vi insert mode, which causes a change to command mode (see p. 13). Locations for executable files. When executing a program, one can state the name of the program with the full directory path to the program’s name. For