09.06.2013 Views

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

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

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

csh: C Shell <strong>XENIX</strong> Programming<br />

Another important mechanism used in C shell scripts is the colon (:) modifier. We can<br />

use the modifier :r here to extract the root of a file name. For example, this gives the<br />

variable i the value /mnt/foo.bar:<br />

% set i = /mnt/foo.bar<br />

If you give this command:<br />

% echo $i $i:r<br />

the result is<br />

/mnt/foo.bar /mnt/foo<br />

This example shows how the :r modifier strips off the trailing ".bar". Other modifiers<br />

take off the last component of a path name leaving the head :h or all but the last<br />

component of a path name leaving the tail :t. These modifiers are fully described in the<br />

entry csh in Appendix B, "Programming Commands." You can also use the command<br />

substitution mechanism to perform modifications on strings and then re-enter the C<br />

shell environment. Since each usage of this mechanism involves the creation of a new<br />

process, it is much more expensive to use than the colon (:) modification mechanism.<br />

Note also that the current implementation of the C shell limits the number of colon<br />

modifiers on a "$" substitution to 1. Thus<br />

produces<br />

% set i = /albic<br />

% echo $i $i:h:t<br />

!albic /a/b:t<br />

and does not do what you might expect.<br />

Finally, we note that the number sign (#) lexically introduces a C shell comment in C<br />

shell scripts (but not from the terminal). All subsequent characters on the input line<br />

after a number sign are discarded by the C shell. This character can be quoted using ' or<br />

\ to place it in an argument word.<br />

Using Other Control Structures<br />

The C shell also has control structures while and swi<strong>tc</strong>h similar to those of C. These<br />

take the forms<br />

and<br />

8-16<br />

while ( expression )<br />

commands<br />

end

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

Saved successfully!

Ooh no, something went wrong!