|
SECTION 5 ABBREVIATION AND ARGUMENT SUBSTITUTION There are on Multics several commands that enhance your ability to type command lines efficiently. Two of these commands - abbrev and do - will be discussed in this section, and a third - exec_com - will be discussed in Section 6. THE abbrev COMMAND The abbrev command enables you to create your own abbreviations for the elements you use in command lines. For instance, if you found yourself repeatedly changing to another working directory with a command like the following:
you could create an abbreviation for the pathname in order to avoid typing the lengthier form. The command line might then be as short as:
The letter "J" would be expanded to the character string it represents, in this case ">udd>Training>Jones, " and the command would then process with this pathname. You create abbreviations by invoking the abbrev command and then using a command-like invocation called an abbrev request line. To illustrate this first step, let's look at how you would create the abbreviation for ">udd>Training>Jones." First, you invoke the abbrev command:
When invoked, the abbrev command returns no output: you simply get a ready message. But once invoked the abbrev command remains in effect until you cancel it. That is done by issuing an abbrev request line:
You may seldom find it necessary to issue this quit request. In fact, the abbrev procedure is so useful for minimizing typing at the terminal that users often include the abbrev command in their start_up.ec (see Section 6 in this manual) so that it is automatically invoked every time they log in. It is while the abbrev command is in effect that you can create, delete, and change abbreviations and use them in command lines. To create an abbreviation you must type a request line, which begins with a period (.) in the first non-blank space. To create an abbreviation that will be expanded no matter where it appears in a command line, you use the control request .a:
This request line places the abbreviation "J" in a special segment that is labelled with your Person_id and a suffix of profile (e.g., Smith.profile). All of your abbreviations are stored in this segment, unless you specifically place some in other segments. You may, if you wish, have several separate segments for abbreviations. You would then specify with the abbrev request ".u" which group of abbreviations you'd like to use at that time. For the sake of simplicity, we'll assume here that all abbreviations are being placed in one segment named Smith.profile. So far, we've placed one abbreviation in this segment:
Now it can be used as an abbreviation anytime the abbrev command is in effect. When it is invoked, the abbrev command sets up a special processor, called the abbrev processor, which works on each command line input to the system. This processor scans each line to detect and expand abbreviations and then passes the command line on to the normal command processor. In this process abbreviations are expanded only once, so you cannot nest abbreviations. To continue our illustration of the abbrev command feature on Multics, let's look at another type of abbreviation, one which is expanded only when it appears at the beginning of a line. Such a specific entry would be useful for the abbreviation of an entire command line or a part of the line that includes the command name. You might do this with the command line used above to change your working directory. In order to indicate that this abbreviation is to be expanded only when it appears at the beginning of a command line, type:
Thus, to change to this particular directory, you would type only:
You'll no doubt find need for a number of abbreviations, and to keep track of what they are, you'll occasionally want to read your profile segment. To do this while the abbrev command is in effect, you simply type:
You will then have a list like the following printed at your terminal:
The first six abbreviations shown here will be expanded if they appear anywhere in the command line. The lower case "b" to the left of the last abbreviation indicates that it will be expanded only when it appears at the beginning of a command line. Any abbreviation you create must be no more than eight characters long, and when you type it into a command line it must be bounded by break characters. And of course this latter condition makes it impossible for the abbreviation itself to contain any break characters. The characters that the abbrev processor treats as breaks are:
You will notice that the last seven characters in this list are those that were called reserved characters in Section 2. It is important to remember that while these characters are being used for the special purposes described earlier, they will also serve as break characters and thus possibly set off any abbreviations you are using. To be on the safe side, you should only use break and reserved characters when you have a specific need for them. That should prevent the expansion of characters by the abbrev processor when you do not mean them to be interpreted as abbreviations. In cases where you want to use characters that are defined as abbreviations for some other purpose, you can prevent the abbrev processor from expanding them by enclosing them in quotation marks. For instance, if you want to change working directories using a pathname that contains the entryname arc, you couldn't type:
Because the string arc is defined as an abbreviation in your profile segment, this pathname would be expanded to:
The command would probably not be able to find a directory by that expanded name and thus would return on error message:
But this expansion could be suppressed by quotation marks:
It could also be suppressed by the request .<space>:
By beginning the command line with a period and a space, you suppress expansion of the entire line, that is, no abbreviations contained in the line will be expanded. An effective way of avoiding unanticipated expansions is to use capital letters in abbreviations. Since Multics command language uses lower case letters, it is very unlikely that any string you use from command language will ever be confused with an abbreviation if your abbreviations use upper case letters. For instance, the entryname "arc" could not be confused with the abbreviation for "art_customers" if the latter used a capital A - "Arc." Your existing abbreviations are also checked when you are adding abbreviations. If an abbreviation you are creating already exists, you will be asked whether or not you actually do wish to redefine it. You simply respond "yes" or "no". THE do COMMAND The do command enables you to substitute arguments in a command line before executing the line. This is particularly useful for command lines that repeat a certain argument a number of times, such as those containing multiple commands. Let's return to the segments containing plans that we used in previous illustrations. Suppose you are about to compose a new set of plans and want to discard your old plans. You decide to print a copy of the segment old.plans "before deleting it, and you want to rename your most recent plans, currently in the segment named new.plans, to old.plans. To do this you could type:
But with the do command you could avoid retyping the segment names by referring to them with special symbols included in the command line:
Numbers preceded by an ampersand (&) refer to arguments listed after the quoted portion of the do command line. In the example, "new.plans" is substituted for the &1 string at each point where &1 appears because "new.plans" is in the first position after the quoted portion of the command line. Likewise, "old.plans" substitutes for &2 because it is in the second position after the quoted string, separated from the first by a blank space. So, the above command line would expand to the following when the do command is executed:
This, of course, is the command we originally wanted to type. It is important to note here that if an argument is not supplied, nothing will be inserted in the places where the extra number and ampersand appears. The last argument would not be used to substitute for the extra places. For instance, if the command line shown above had an &3, it would be ignored:
would be expanded to:
After the print command executed, the delete command would return an error message because it has not been supplied with a pathname:
If, on the other hand, the command could execute regardless of the empty argument, it would not return an error message; it would go ahead and execute. The do command is particularly useful in conjunction with the abbrev command. Earlier it was noted that abbreviations cannot be nested because the abbrev processor scans a command line only once. But the do command makes, in effect, two command lines out of one, so the abbrev processor does scan the command twice in this case, though of course it will not expand any abbreviations within the quoted command string during the first scan. You might, for example, use "P" as an abbreviation for "plans" in the command line shown above and thus type:
The "P" would first be expanded:
and then substituted, producing the expansion shown earlier:
Often-used do command lines can even be added to your profile segment, a practice that will enable you to make very long command strings very easy to type. Take as an example one of the lines typed above and create an abbreviation for it, using the additional abbreviation "P" just suggested: ! .ab PLAN do "print &2; delete &2; rename &1 &2" This will then reduce typing of the above string with new.plans and old.plans as the do command arguments to:
This expands first to:
and then the do command is executed, producing:
Because the do command uses quotation marks, it is necessary that we now understand further the convention of quoted strings in the Multics command language. We noted in Section 2 that quotation marks are used for passing characters exactly as they are typed on the terminal, that is, suppressing the interpretation normally applied to them. As we have just seen above, they can be used in this manner to suppress the expansion of an abbreviation. But when one set of quotation marks is included within another set of quotation marks, as is quite likely with the do command, the inner quotes must be doubled. For Instance, if you apply the do command to the sort_list command line used as an example in Section 2:
it becomes:
The inner quotation marks must "be doubled because characters are interpreted individually from left to right. Thus the single quotation mark followed by another type of character (e.g., "sort_list &1 -sort "lastname...) would be interpreted as the end of the quoted string that began with the first quotation mark. In that case, the quoted portion of the do command line would appear to be "sort_list &1 -sort" and everything following it would be interpreted by the command processor as arguments for substitution. That, of course, is not the intention at all. But as it is in the above command line. the doubled quotation marks are interpreted as single marks (") because they are enclosed within the outer quotation marks of the do command line. So, after the do command substitutes the argument, the command line is what we had in the original example:
because the double quotation marks have been reduced to single marks by the do command.
<< Previous Section Next Section >> Contents | 1 | 2 | 3 | 4 | 5 | 6 | 7 | A | B | C
|