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 csh: C Shell Sometimes a nu mber of locally developed programs reside in the directory /usr/local. If you want all C shells that you invoke to have access to these new programs, place the command set path =(. /bin /usr/bi n /usr/local) in the .cshrc file in your home directory. Try doing this, then logging out and back in. Type set to see that the value assigned to path has changed. When you log in, the C shell examines all directories in your path other than the current directory (.), to determine which commands are in those directories. The C shell remembers these commands in an internal table. This means that if a command is added to a directory in your search path after you have started the C shell, then the C shell may not find that command if you attempt to invoke it. If you want to use a command that has been added after you have logged in, give the command rehash to the C shell. rehash causes the shell to recompute its internal table of command locations, so that it will find the newly added command. Note that rehashing is not necessary for commands added to the current directory. Since the C shell has to look in the current directory on each command anyway, placing it at the end of the path specification usually works best and reduces overhead. Other useful built-in variables are home, which shows your home directory, and ignoreeof, which can be set in your .login file to tell the C shell not to exit when it receives an end-of-file from a terminal. The variable ignoreeof is one of several variables with values that the C shell does not care about; the C shell is only concerned with whether these variables are set or unset. Thus, to set ignoreeof you simply type set ignoreeof and to unset it type unset ignoreeof Some other useful built-in C shell variables are noclobber and mail. The syntax > filename which redirects the standard output of a command just as in the regular shell, overwrites and destroys the previous contents of the named file. In this way, you may accidentally overwrite a valuable file. If you prefer that the C shell not overwrite files in this way, type set noclobber 8-3

csh: C Shell XENIX Programming in your .login file. After setting noclobber, typing date > now causes an error message if the file now already exists. You can type date >! now if you really want to overwrite the contents of now. The " > !" is a special syntax indicating that overwriting or "clobbering" the file is permitted. (The space between the exclamation point (!) and the word "now" is critical here, as "!now" would be an invocation of the history mechanism (described below) and would have a very different effect.) Using the C Shell History List The C shell can maintain a history list containing the text of previous commands. You can use a notation that reuses commands, or words from commands, in forming new commands. This notation can be used to repeat previous commands or to correct minor typing mistakes in commands. The following example gives a sample session using the history mechanism of the C shell. The example assumes that the bug.c file exists and that its contents are exactly as shown below. Boldface indicates user input. 8-4 % cat bug.c main( ) { printf("hello); } % cc !$ cc bug.c bug.c (5) : warning 8: newline in string constant bug.c (5): error 59 : syntax error: ' } ' % ed !$ ed bug.c 29 * 4s/);/");/p printf(" hello"); *w 30 * q % !c cc bug.c % a.out hello% !e ed bug.c 30 * 4s/lo/lo\\n/p pri ntf(" hello\n ");

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

in your .login file. After setting noclobber, typing<br />

date > now<br />

causes an error message if the file now already exists. You can type<br />

date >! now<br />

if you really want to overwrite the contents of now. The " > !" is a special syntax<br />

indicating that overwriting or "clobbering" the file is permitted. (The space between<br />

the exclamation point (!) and the word "now" is critical here, as "!now" would be an<br />

invocation of the history mechanism (described below) and would have a very different<br />

effect.)<br />

Using the C Shell History List<br />

The C shell can maintain a history list containing the text of previous commands. You<br />

can use a notation that reuses commands, or words from commands, in forming new<br />

commands. This notation can be used to repeat previous commands or to correct minor<br />

typing mistakes in commands.<br />

The following example gives a sample session using the history mechanism of the C<br />

shell. The example assumes that the bug.c file exists and that its contents are exactly<br />

as shown below. Boldface indicates user input.<br />

8-4<br />

% cat bug.c<br />

main( )<br />

{<br />

printf("hello);<br />

}<br />

% cc !$<br />

cc bug.c<br />

bug.c (5) : warning 8: newline in string constant<br />

bug.c (5): error 59 : syntax error: ' } '<br />

% ed !$<br />

ed bug.c<br />

29<br />

* 4s/);/");/p<br />

printf(" hello");<br />

*w<br />

30<br />

* q<br />

% !c<br />

cc bug.c<br />

% a.out<br />

hello% !e<br />

ed bug.c<br />

30<br />

* 4s/lo/lo\\n/p<br />

pri ntf(" hello\n ");

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

Saved successfully!

Ooh no, something went wrong!