Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming Programming Commands csh (continued) To select words from an event, we can follow the event specification by a colon (:) and a designator for the desired words. The words of an input line are nu mbered from 0, the first (usually command) word being 0, the second word (first argument) being 1, and so on. The basic word designators are 0 First (command) word n nth argument First argument (that is, 1) $ Last argument 96 Word matched by (immediately preceding) ?s? search x-y Range of words -y Abbreviates 0-y * Abbreviates "-$, or nothing if only one word in event x* Abbreviates x-$ x- Like x* but omitting word $ The : separating the event specification from the word designator can be omitted if the argument selector begins with a " , $, *, -, or %. A sequence of modifiers, each preceded by a colon, can be placed after the optional word designator. The following modifiers are defined: h Removes a trailing path name component r Removes a trailing .xx:x component s/l/r/ Substitutes l for r t Removes all leading path name components c5c Repeats the previous substitution g Applies the change globally, prefixing the above p Prints the new command but do not execute it q Quotes the substituted words, preventing substitutions X Like q, but breaks into words at blanks, tabs, and newlines The modification is applied only to the first modifiable word unless preceded by a g. In any case, it is an error for no word to be applicable. B-37

Programming Commands XENIX Programming csh (continued) The left sides of substitutions are strings, not regular expressions in the sense of the editors. Any character can be used in place of slash {/) as the delimiter. A backslash {\) quotes the delimiter into the 1 and r strings. An & in the right side is replaced by the text from the left. A \ quotes &. A null l uses the previous string either from an l or from a contextual scan string s in !?s?. The trailing delimiter in a substitution or the trailing ? in a contextual scan can be omitted if a newline follows immediately. A history reference may be given without an event specification, for example, !$. In this case, the reference is to the previous command unless a previous history reference occurred on the same line, in which case this form repeats the previous reference. Thus !?foo?"!$ gives the first and last arguments from the command matching ?foo?. A special abbreviation of a history reference occurs when the first nonblank character of an input · line is a caret ('"'). This is equivalent to !:s" and provides a convenient shorthand for substitutions on the text of the previous line. Thus, "lb"lib fixes the spelling of lib in the previous command. Finally, a history substitution may be surrounded with braces ({ }) if necessary to insulate it from the characters that follow. Thus, after Is -ld-paul we might do !{I}a to do Is -ld-paula, while !la would look for a command starting Ia. Quotations with ' and " The quotation of strings by ' and " can be used to prevent all or some of the remaining substitutions. Strings enclosed in ' are prevented any further interpretation. Strings enclosed in " are variable, and command expansion may occur.In both cases, the resulting text becomes (all or part of) a single word. Only in one special case (see "Command Substitution" later in this entry) does a " quoted string yield parts of more than one word; ' quoted strings never do. Alias Substitution The shell maintains a list of aliases that can be established, displayed, and modified by the alias and unalias commands. After a command line is scanned, it is parsed into distinct commands, and the first word of each command, left-to-right, is checked to see if it has an alias. If it does, then the text that is the alias for that command is reread with the history mechanism available as though that command were the previous input line. The resulting words replace the command and argument list. If no reference is made to the history list, then the argument list is left unchanged. Thus if the alias for Is is Is -1 the command "Is /usr" would map to "Is -1 /usr". Similarly, if the alias for lookup was grep "!" /etc/passwd" then "lookup bill" would map to "grep bill /etc/passwd". If an alias is found, the word transformation of the input text is performed, and the aliasing process begins again on the reformed input line. If the first word of the new text is the same as the old, flagging it will prevent further aliasing and will preclude looping. Other loops are detected and cause an error. The mechanism allows aliases to introduce parser metasyntax. Thus, we can alias print as "'pr\!* I lpr"' to make a command that paginates its arguments to the line printer. B-38

<strong>XENIX</strong> Programming Programming Commands<br />

csh (continued)<br />

To select words from an event, we can follow the event specification by a colon (:) and<br />

a designator for the desired words. The words of an input line are nu mbered from 0, the<br />

first (usually command) word being 0, the second word (first argument) being 1, and so<br />

on. The basic word designators are<br />

0 First (command) word<br />

n nth argument<br />

First argument (that is, 1)<br />

$ Last argument<br />

96 Word ma<strong>tc</strong>hed by (immediately preceding) ?s? search<br />

x-y Range of words<br />

-y Abbreviates 0-y<br />

* Abbreviates "-$, or nothing if only one word in event<br />

x* Abbreviates x-$<br />

x- Like x* but omitting word $<br />

The : separating the event specification from the word designator can be omitted if the<br />

argument selector begins with a " , $, *, -, or %. A sequence of modifiers, each<br />

preceded by a colon, can be placed after the optional word designator. The following<br />

modifiers are defined:<br />

h Removes a trailing path name component<br />

r Removes a trailing .xx:x component<br />

s/l/r/ Substitutes l for r<br />

t Removes all leading path name components<br />

c5c Repeats the previous substitution<br />

g Applies the change globally, prefixing the above<br />

p Prints the new command but do not execute it<br />

q Quotes the substituted words, preventing substitutions<br />

X Like q, but breaks into words at blanks, tabs, and newlines<br />

The modification is applied only to the first modifiable word unless preceded by a g. In<br />

any case, it is an error for no word to be applicable.<br />

B-37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!