Merge branch 'vendor/OPENSSH'
[dragonfly.git] / bin / csh / USD.doc / csh.1
1 .\" Copyright (c) 1980, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)csh.1       8.1 (Berkeley) 6/8/93
29 .\" $FreeBSD: src/bin/csh/USD.doc/csh.1,v 1.9.2.2 2003/01/24 02:12:02 keramida Exp $
30 .\" $DragonFly: src/bin/csh/USD.doc/csh.1,v 1.2 2003/06/17 04:22:49 dillon Exp $
31 .\"
32 .EH 'USD:4-%''An Introduction to the C shell'
33 .OH 'An Introduction to the C shell''USD:4-%'
34 .\".RP
35 .TL
36 An Introduction to the C shell
37 .AU
38 William Joy
39 (revised for 4.3BSD by Mark Seiden)
40 .AI
41 Computer Science Division
42 .br
43 Department of Electrical Engineering and Computer Science
44 .br
45 University of California, Berkeley
46 .br
47 Berkeley, California 94720
48 .AB
49 .I Csh
50 is a new command language interpreter for
51 .UX
52 systems.
53 It incorporates good features of other shells and a
54 .I history
55 mechanism similar to the
56 .I redo
57 of \s-2INTERLISP\s0.
58 While incorporating many features of other shells which make
59 writing shell programs (shell scripts) easier,
60 most of the features unique to
61 .I csh
62 are designed more for the interactive \s-2UNIX\s0 user.
63 .PP
64 \s-2UNIX\s0
65 users who have read a general introduction to the system
66 will find a valuable basic explanation of the shell here.
67 Simple terminal interaction with
68 .I csh
69 is possible after reading just the first section of this document.
70 The second section describes the shell's capabilities which you can
71 explore after you have begun to become acquainted with the shell.
72 Later sections introduce features which are useful, but not necessary
73 for all users of the shell.
74 .PP
75 Additional information includes an appendix listing special characters of the shell
76 and a glossary of terms and commands introduced in this manual.
77 .AE
78 .SH
79 .if n .ND
80 Introduction
81 .PP
82 A
83 .I shell
84 is a command language interpreter.
85 .I Csh
86 is the name of one particular command interpreter on
87 \s-2UNIX\s0.
88 The primary purpose of
89 .I csh
90 is to translate command lines typed at a terminal into
91 system actions, such as invocation of other programs.
92 .I Csh
93 is a user program just like any you might write.
94 Hopefully,
95 .I csh
96 will be a very useful program for you
97 in interacting with the \s-2UNIX\s0 system.
98 .PP
99 In addition to this document, you will want to refer to a copy
100 of the \s-2UNIX\s0 User Reference Manual.
101 The
102 .I csh
103 documentation in section 1 of the manual provides a full description of all
104 features of the shell and is the definitive reference for questions
105 about the shell.
106 .PP
107 Many words in this document are shown in
108 .I italics.
109 These are important words;
110 names of commands, and words which have special meaning in discussing
111 the shell and \s-2UNIX\s0.
112 Many of the words are defined in a glossary at the end of this document.
113 If you don't know what is meant by a word, you should look
114 for it in the glossary.
115 .SH
116 Acknowledgements
117 .PP
118 Numerous people have provided good input about previous versions
119 of
120 .I csh
121 and aided in its debugging and in the debugging of its documentation.
122 I would especially like to thank Michael Ubell
123 who made the crucial observation that history commands could be
124 done well over the word structure of input text, and implemented
125 a prototype history mechanism in an older version of the shell.
126 Eric Allman has also provided a large number of useful comments on the
127 shell, helping to unify those concepts which are present and to identify
128 and eliminate useless and marginally useful features.
129 Mike O'Brien suggested the pathname hashing
130 mechanism which speeds command execution.
131 Jim Kulp added the job control and directory stack primitives and
132 added their documentation to this introduction.
133 .br
134 .bp
135 .NH
136 Terminal usage of the shell
137 .NH 2
138 The basic notion of commands
139 .PP
140 A
141 .I shell
142 in
143 \s-2UNIX\s0
144 acts mostly as a medium through which other
145 .I programs
146 are invoked.
147 While it has a set of
148 .I builtin
149 functions which it performs directly,
150 most commands cause execution of programs that are, in fact,
151 external to the shell.
152 The shell is thus distinguished from the command interpreters of other
153 systems both by the fact that it is just a user program, and by the fact
154 that it is used almost exclusively as a mechanism for invoking other programs.
155 .PP
156 .I Commands
157 in the \s-2UNIX\s0 system consist of a list of strings or
158 .I words
159 interpreted as a
160 .I "command name"
161 followed by
162 .I arguments.
163 Thus the command
164 .DS
165 mail bill
166 .DE
167 consists of two words.
168 The first word
169 .I mail
170 names the command to be executed, in this case the
171 mail program which sends messages to other users.
172 The shell uses the name of the command in attempting to execute it for you.
173 It will look in a number of
174 .I directories
175 for a file with the name
176 .I mail
177 which is expected to contain the mail program.
178 .PP
179 The rest of the words of the command are given as
180 .I arguments
181 to the command itself when it is executed.
182 In this case we specified also the argument
183 .I bill
184 which is interpreted by the
185 .I mail
186 program to be the name of a user to whom mail is to be sent.
187 In normal terminal usage we might use the
188 .I mail
189 command as follows.
190 .DS
191 % mail bill
192 I have a question about the csh documentation.
193 My document seems to be missing page 5.
194 Does a page five exist?
195         Bill
196 EOT
197 %
198 .DE
199 .PP
200 Here we typed a message to send to
201 .I bill
202 and ended this message with a ^D which sent an end-of-file to
203 the mail program.
204 (Here and throughout this document, the notation ``^\fIx\fR''
205 is to be read ``control-\fIx\fR'' and represents the striking of the \fIx\fR
206 key while the control key is held down.)
207 The mail program
208 then echoed the characters `EOT' and transmitted our message.
209 The characters `% ' were printed before and after the mail command
210 by the shell to indicate that input was needed.
211 .PP
212 After typing the `% ' prompt the shell was reading command input from
213 our terminal.
214 We typed a complete command `mail bill'.
215 The shell then executed the
216 .I mail
217 program with argument
218 .I bill
219 and went dormant waiting for it to complete.
220 The mail program then read input from our terminal until we signalled
221 an end-of-file via typing a ^D after which the shell noticed
222 that mail had completed
223 and signaled us that it was ready to read from the terminal again by
224 printing another `% ' prompt.
225 .PP
226 This is the essential pattern of all interaction with \s-2UNIX\s0
227 through the shell.
228 A complete command is typed at the terminal, the shell executes
229 the command and when this execution completes, it prompts for a new command.
230 If you run the editor for an hour, the shell will patiently wait for
231 you to finish editing and obediently prompt you again whenever you finish
232 editing.
233 .PP
234 An example of a useful command you can execute now is the
235 .I tset
236 command, which sets the default
237 .I erase
238 and
239 .I kill
240 characters on your terminal \- the erase character erases the last
241 character you typed and the kill character erases the entire line you
242 have entered so far.
243 By default, the erase character is the delete key (equivalent to `^?')
244 and the kill character is `^U'.  Some people prefer to make the erase character
245 the backspace key (equivalent to `^H').
246 You can make this be true by typing
247 .DS
248 tset \-e
249 .DE
250 which tells the program
251 .I tset
252 to set the erase character to tset's default setting for this character
253 (a backspace).
254 .NH 2
255 Flag arguments
256 .PP
257 A useful notion in \s-2UNIX\s0 is that of a
258 .I flag
259 argument.
260 While many arguments to commands specify file names or user names,
261 some arguments rather specify an optional capability of the command
262 which you wish to invoke.
263 By convention, such arguments begin with the character `\-' (hyphen).
264 Thus the command
265 .DS
266 ls
267 .DE
268 will produce a list of the files in the current
269 .I "working directory" .
270 The option
271 .I \-s
272 is the size option, and
273 .DS
274 ls \-s
275 .DE
276 causes
277 .I ls
278 to also give, for each file the size of the file in blocks of 512
279 characters.
280 The manual section for each command in the \s-2UNIX\s0 reference manual
281 gives the available options for each command.
282 The
283 .I ls
284 command has a large number of useful and interesting options.
285 Most other commands have either no options or only one or two options.
286 It is hard to remember options of commands which are not used very
287 frequently, so most \s-2UNIX\s0 utilities perform only one or two functions
288 rather than having a large number of hard to remember options.
289 .NH 2
290 Output to files
291 .PP
292 Commands that normally read input or write output on the terminal
293 can also be executed with this input and/or output done to
294 a file.
295 .PP
296 Thus suppose we wish to save the current date in a file called `now'.
297 The command
298 .DS
299 date
300 .DE
301 will print the current date on our terminal.
302 This is because our terminal is the default
303 .I "standard output"
304 for the date command and the date command prints the date on its
305 standard output.
306 The shell lets us
307 .I redirect
308 the
309 .I "standard output"
310 of a command through a
311 notation using the
312 .I metacharacter
313 `>' and the name of the file where output is to be placed.
314 Thus the command
315 .DS
316 date > now
317 .DE
318 runs the
319 .I date
320 command such that its standard output is
321 the file `now' rather than the terminal.
322 Thus this command places the current date and time into the file `now'.
323 It is important to know that the
324 .I date
325 command was unaware that its output was going to a file rather than
326 to the terminal.
327 The shell performed this
328 .I redirection
329 before the command began executing.
330 .PP
331 One other thing to note here is that the file `now'
332 need not have existed before the
333 .I date
334 command was executed; the shell would have created the file if it did
335 not exist.
336 And if the file did exist?
337 If it had existed previously these previous contents would have been discarded!
338 A shell option
339 .I noclobber
340 exists to prevent this from happening accidentally;
341 it is discussed in section 2.2.
342 .PP
343 The system normally keeps files which you create with `>' and all other files.
344 Thus the default is for files to be permanent.  If you wish to create a file
345 which will be removed automatically, you can begin its name with a `#'
346 character, this `scratch' character denotes the fact that the file will
347 be a scratch file.*
348 .FS
349 *Note that if your erase character is a `#', you will have to precede the
350 `#' with a `\e'.  The fact that the `#' character is the old (pre-\s-2CRT\s0)
351 standard erase character means that it seldom appears in a file name, and
352 allows this convention to be used for scratch files.  If you are using a
353 \s-2CRT\s0, your erase character should be a ^H, as we demonstrated
354 in section 1.1 how this could be set up.
355 .FE
356 The system will remove such files after a couple of days,
357 or sooner if file space becomes very tight.
358 Thus, in running the
359 .I date
360 command above, we don't really want to save the output forever, so we
361 would more likely do
362 .DS
363 date > #now
364 .DE
365 .NH 2
366 Metacharacters in the shell
367 .PP
368 The shell has a large number of
369 special characters (like `>')
370 which indicate special functions.
371 We say that these notations have
372 .I syntactic
373 and
374 .I semantic
375 meaning to the shell.
376 In general, most characters which are neither letters nor digits
377 have special meaning to the shell.
378 We shall shortly learn a means of
379 .I quotation
380 which allows us to use
381 .I metacharacters
382 without the shell treating them in any special way.
383 .PP
384 Metacharacters normally have effect only when the shell is reading
385 our input.
386 We need not worry about placing shell metacharacters in a letter
387 we are sending via
388 .I mail,
389 or when we are typing in text or data to some other program.
390 Note that the shell is only reading input when it has prompted with
391 `% ' (although we can type our input even before it prompts).
392 .NH 2
393 Input from files; pipelines
394 .PP
395 We learned above how to
396 .I redirect
397 the
398 .I "standard output"
399 of a command
400 to a file.
401 It is also possible to redirect the
402 .I "standard input"
403 of a command from a file.
404 This is not often necessary since most commands will read from
405 a file whose name is given as an argument.
406 We can give the command
407 .DS
408 sort < data
409 .DE
410 to run the
411 .I sort
412 command with standard input, where the command normally
413 reads its input, from the file
414 `data'.
415 We would more likely say
416 .DS
417 sort data
418 .DE
419 letting the
420 .I sort
421 command open the file
422 `data'
423 for input itself since this is less to type.
424 .PP
425 We should note that if we just typed
426 .DS
427 sort
428 .DE
429 then the sort program would sort lines from its
430 .I "standard input."
431 Since we did not
432 .I redirect
433 the standard input, it would sort lines as we typed them on the terminal
434 until we typed a ^D to indicate an end-of-file.
435 .PP
436 A most useful capability is the ability to combine the standard output
437 of one command with the standard input of another, i.e. to run the
438 commands in a sequence known as a
439 .I pipeline.
440 For instance the command
441 .DS
442 ls \-s
443 .DE
444 normally produces a list of the files in our directory with the size
445 of each in blocks of 512 characters.
446 If we are interested in learning which of our files is largest we
447 may wish to have this sorted by size rather than by name, which is
448 the default way in which
449 .I ls
450 sorts.
451 We could look at the many options of
452 .I ls
453 to see if there was an option to do this but would eventually discover
454 that there is not.
455 Instead we can use a couple of simple options of the
456 .I sort
457 command, combining it with
458 .I ls
459 to get what we want.
460 .PP
461 The
462 .I \-n
463 option of sort specifies a numeric sort rather than an alphabetic sort.
464 Thus
465 .DS
466 ls \-s | sort \-n
467 .DE
468 specifies that the output of the
469 .I ls
470 command run with the option
471 .I \-s
472 is to be
473 .I piped
474 to the command
475 .I sort
476 run with the numeric sort option.
477 This would give us a sorted list of our files by size, but with the
478 smallest first.
479 We could then use the
480 .I \-r
481 reverse sort option and the
482 .I head
483 command in combination with the previous command doing
484 .DS
485 ls \-s | sort \-n \-r | head \-5
486 .DE
487 Here we have taken a list of our files sorted alphabetically,
488 each with the size in blocks.
489 We have run this to the standard input of the
490 .I sort
491 command asking it to sort numerically in reverse order (largest first).
492 This output has then been run into the command
493 .I head
494 which gives us the first few lines.
495 In this case we have asked
496 .I head
497 for the first 5 lines.
498 Thus this command gives us the names and sizes of our 5 largest files.
499 .PP
500 The notation introduced above is called the
501 .I pipe
502 mechanism.
503 Commands separated by `\||\|' characters are connected together by the
504 shell and the standard output of each is run into the standard input of the
505 next.
506 The leftmost command in a pipeline will normally take its standard
507 input from the terminal and the rightmost will place its standard
508 output on the terminal.
509 Other examples of pipelines will be given later when we discuss the
510 history mechanism;
511 one important use of pipes which is illustrated there is in the
512 routing of information to the line printer.
513 .NH 2
514 Filenames
515 .PP
516 Many commands to be executed will need the names of files as arguments.
517 \s-2UNIX\s0
518 .I pathnames
519 consist of a number of
520 .I components
521 separated by `/'.
522 Each component except the last names a directory in which the next
523 component resides, in effect specifying the
524 .I path
525 of directories to follow to reach the file.
526 Thus the pathname
527 .DS
528 /etc/motd
529 .DE
530 specifies a file in the directory
531 `etc'
532 which is a subdirectory of the
533 .I root
534 directory `/'.
535 Within this directory the file named is `motd' which stands
536 for `message of the day'.
537 A
538 .I pathname
539 that begins with a slash is said to be an
540 .I absolute
541 pathname since it is specified from the absolute top of the entire
542 directory hierarchy of the system (the
543 .I root ).
544 .I Pathnames
545 which do not begin with `/' are interpreted as starting in the current
546 .I "working directory" ,
547 which is, by default, your
548 .I home
549 directory and can be changed dynamically by the
550 .I cd
551 change directory command.
552 Such pathnames are said to be
553 .I relative
554 to the working directory since they are found by starting
555 in the working directory and descending to lower levels of directories
556 for each
557 .I component
558 of the pathname.  If the pathname contains no slashes at all then the
559 file is contained in the working directory itself and the pathname is merely
560 the name of the file in this directory.
561 Absolute pathnames have no relation
562 to the working directory.
563 .PP
564 Most filenames consist of a number of alphanumeric characters and
565 `.'s (periods).
566 In fact, all printing characters except `/' (slash) may appear in filenames.
567 It is inconvenient to have most non-alphabetic characters in filenames
568 because many of these have special meaning to the shell.
569 The character `.' (period) is not a shell-metacharacter and is often used
570 to separate the
571 .I extension
572 of a file name from the base of the name.
573 Thus
574 .DS
575 prog.c prog.o prog.errs prog.output
576 .DE
577 are four related files.
578 They share a
579 .I base
580 portion of a name
581 (a base portion being that part of the name that is left when a trailing
582 `.' and following characters which are not `.' are stripped off).
583 The file
584 `prog.c'
585 might be the source for a C program,
586 the file `prog.o' the corresponding object file,
587 the file
588 `prog.errs' the errors resulting from a compilation of the program
589 and the file
590 `prog.output' the output of a run of the program.
591 .PP
592 If we wished to refer to all four of these files in a command, we could
593 use the notation
594 .DS
595 prog.*
596 .DE
597 This expression is expanded by the shell, before the command to which it is
598 an argument is executed, into a list of names which begin with `prog.'.
599 The character `*' here matches any sequence (including the empty sequence)
600 of characters in a file name.
601 The names which match are alphabetically sorted and placed in the
602 .I "argument list"
603 of the command.
604 Thus the command
605 .DS
606 echo prog.*
607 .DE
608 will echo the names
609 .DS
610 prog.c prog.errs prog.o prog.output
611 .DE
612 Note that the names are in sorted order here, and a different
613 order than we listed them above.
614 The
615 .I echo
616 command receives four words as arguments, even though we only typed
617 one word as an argument directly.
618 The four words were generated by
619 .I "filename expansion"
620 of the one input word.
621 .PP
622 Other notations for
623 .I "filename expansion"
624 are also available.
625 The character `?' matches any single character in a filename.
626 Thus
627 .DS
628 echo ? \|?? \|???
629 .DE
630 will echo a line of filenames; first those with one character names,
631 then those with two character names, and finally those with three
632 character names.
633 The names of each length will be independently sorted.
634 .PP
635 Another mechanism consists of a sequence of characters between `[' and `]'.
636 This metasequence matches any single character from the enclosed set.
637 Thus
638 .DS
639 prog.[co]
640 .DE
641 will match
642 .DS
643 prog.c prog.o
644 .DE
645 in the example above.
646 We can also place two characters around a `\-' in this notation to denote
647 a range.
648 Thus
649 .DS
650 chap.[1\-5]
651 .DE
652 might match files
653 .DS
654 chap.1 chap.2 chap.3 chap.4 chap.5
655 .DE
656 if they existed.
657 This is shorthand for
658 .DS
659 chap.[12345]
660 .DE
661 and otherwise equivalent.
662 .PP
663 An important point to note is that if a list of argument words to
664 a command (an
665 .I "argument list)"
666 contains filename expansion syntax, and if this filename expansion syntax
667 fails to match any existing file names, then the shell considers this
668 to be an error and prints a diagnostic
669 .DS
670 No match.
671 .DE
672 and does not execute the command.
673 .PP
674 Another very important point is that files with the character `.' at the
675 beginning are treated specially.
676 Neither `*' or `?' or the `[' `]' mechanism will match it.
677 This prevents accidental matching of the filenames `.' and `..'
678 in the working directory which have special meaning to the system,
679 as well as other files such as
680 .I \&.cshrc
681 which are not normally
682 visible.
683 We will discuss the special role of the file
684 .I \&.cshrc
685 later.
686 .PP
687 Another filename expansion mechanism gives access to the pathname of
688 the
689 .I home
690 directory of other users.
691 This notation consists of the character `~' (tilde) followed by another user's
692 login name.
693 For instance the word `~bill' would map to the pathname `/usr/bill'
694 if the home directory for `bill' was `/usr/bill'.
695 Since, on large systems, users may have login directories scattered over
696 many different disk volumes with different prefix directory names,
697 this notation provides a convenient way of accessing the files
698 of other users.
699 .PP
700 A special case of this notation consists of a `~' alone, e.g. `~/mbox'.
701 This notation is expanded by the shell into the file `mbox' in your
702 .I home
703 directory, i.e. into `/usr/bill/mbox' for me on Ernie Co-vax, the UCB
704 Computer Science Department VAX machine, where this document was prepared.
705 This can be very useful if you have used
706 .I cd
707 to change to another directory and have found a file you wish to
708 copy using
709 .I cp.
710 If I give the command
711 .DS
712 cp thatfile ~
713 .DE
714 the shell will expand this command to
715 .DS
716 cp thatfile /usr/bill
717 .DE
718 since my home directory is /usr/bill.
719 .PP
720 There also exists a mechanism using the characters `{' and `}' for
721 abbreviating a set of words which have common parts but cannot
722 be abbreviated by the above mechanisms because they are not files,
723 are the names of files which do not yet exist,
724 are not thus conveniently described.
725 This mechanism will be described much later,
726 in section 4.2,
727 as it is used less frequently.
728 .NH 2
729 Quotation
730 .PP
731 We have already seen a number of metacharacters used by the shell.
732 These metacharacters pose a problem in that we cannot use them directly
733 as parts of words.
734 Thus the command
735 .DS
736 echo *
737 .DE
738 will not echo the character `*'.
739 It will either echo a sorted list of filenames in the
740 current
741 .I "working directory,"
742 or print the message `No match' if there are
743 no files in the working directory.
744 .PP
745 The recommended mechanism for placing characters which are neither numbers,
746 digits, `/', `.' or `\-' in an argument word to a command is to enclose
747 it with single quotation characters `\'', i.e.
748 .DS
749 echo \'*\'
750 .DE
751 There is one special character `!' which is used by the
752 .I history
753 mechanism of the shell and which cannot be
754 .I escaped
755 by placing it within `\'' characters.
756 It and the character `\'' itself can be preceded by a single `\e'
757 to prevent their special meaning.
758 Thus
759 .DS
760 echo \e\'\e!
761 .DE
762 prints
763 .DS
764 \'!
765 .DE
766 These two mechanisms suffice to place any printing character into a word
767 which is an argument to a shell command.  They can be combined, as in
768 .DS
769 echo \e\'\'*\'
770 .DE
771 which prints
772 .DS
773 \'*
774 .DE
775 since the first `\e' escaped the first `\'' and the `*' was enclosed
776 between `\'' characters.
777 .NH 2
778 Terminating commands
779 .PP
780 When you are executing a command and the shell is
781 waiting for it to complete there are several ways
782 to force it to stop.
783 For instance if you type the command
784 .DS
785 cat /etc/passwd
786 .DE
787 the system will print a copy of a list of all users of the system
788 on your terminal.
789 This is likely to continue for several minutes unless you stop it.
790 You can send an
791 \s-2INTERRUPT\s0
792 .I signal
793 to the
794 .I cat
795 command by typing ^C on your terminal.*
796 .FS
797 *On some older Unix systems the \s-2DEL\s0 or \s-2RUBOUT\s0 key
798 has the same effect. "stty all" will tell you the INTR key value.
799 .FE
800 Since
801 .I cat
802 does not take any precautions to avoid or otherwise handle this signal
803 the
804 \s-2INTERRUPT\s0
805 will cause it to terminate.
806 The shell notices that
807 .I cat
808 has terminated and prompts you again with `% '.
809 If you hit \s-2INTERRUPT\s0 again, the shell will just
810 repeat its prompt since it handles \s-2INTERRUPT\s0 signals
811 and chooses to continue to execute commands rather than terminating
812 like
813 .I cat
814 did, which would have the effect of logging you out.
815 .PP
816 Another way in which many programs terminate is when they get an end-of-file
817 from their standard input.
818 Thus the
819 .I mail
820 program in the first example above was terminated when we typed a ^D
821 which generates an end-of-file from the standard input.
822 The shell also terminates when it gets an end-of-file printing `logout';
823 \s-2UNIX\s0 then logs you off the system.
824 Since this means that typing too many ^D's can accidentally log us off,
825 the shell has a mechanism for preventing this.
826 This
827 .I ignoreeof
828 option will be discussed in section 2.2.
829 .PP
830 If a command has its standard input redirected from a file, then it will
831 normally terminate when it reaches the end of this file.
832 Thus if we execute
833 .DS
834 mail bill < prepared.text
835 .DE
836 the mail command will terminate without our typing a ^D.
837 This is because it read to the end-of-file of our file
838 `prepared.text' in which we placed a message for `bill' with an editor program.
839 We could also have done
840 .DS
841 cat prepared.text \||\| mail bill
842 .DE
843 since the
844 .I cat
845 command would then have written the text through the pipe to the
846 standard input of the mail command.
847 When the
848 .I cat
849 command completed it would have terminated,
850 closing down the pipeline
851 and the
852 .I mail
853 command would have received an end-of-file from it and terminated.
854 Using a pipe here is more complicated than redirecting input
855 so we would more likely use the first form.
856 These commands could also have been stopped by sending an \s-2INTERRUPT\s0.
857 .PP
858 Another possibility for stopping a command is to suspend its execution
859 temporarily, with the possibility of continuing execution later.  This is
860 done by sending a \s-2STOP\s0 signal via typing a ^Z.
861 This signal causes all commands running on the terminal
862 (usually one but more if a pipeline is executing) to become suspended.
863 The shell notices that the command(s) have been suspended, types
864 `Stopped' and then prompts for a new command.
865 The previously executing command has been suspended, but otherwise
866 unaffected by the \s-2STOP\s0 signal.  Any other commands can be executed
867 while the original command remains suspended.  The suspended command can
868 be continued using the
869 .I fg
870 command with no arguments.  The shell will then retype the command
871 to remind you which command is being continued, and cause the command
872 to resume execution.  Unless any input files in use by the suspended
873 command have been changed in the meantime, the suspension has no effect
874 whatsoever on the execution of the command.  This feature can be very useful
875 during editing, when you need to look at another file before continuing.
876 An
877 example of command suspension follows.
878 .DS
879 % mail harold
880 Someone just copied a big file into my directory and its name is
881 ^Z
882 Stopped
883 % ls
884 funnyfile
885 prog.c
886 prog.o
887 % jobs
888 .ta 1.75i
889 [1]  + Stopped  mail harold
890 % fg
891 mail harold
892 funnyfile. Do you know who did it?
893 EOT
894 %
895 .so tabs
896 .DE
897 In this example someone was sending a message to Harold and forgot the
898 name of the file he wanted to mention.  The mail command was suspended
899 by typing ^Z.  When the shell noticed that the mail program was
900 suspended, it typed `Stopped' and prompted for a new command.  Then the
901 .I ls
902 command was typed to find out the name of the file.  The
903 .I jobs
904 command was run to find out which command was suspended.
905 At this time the
906 .I fg
907 command was typed to continue execution of the mail program.  Input
908 to the mail program was then continued and ended with a ^D
909 which indicated the end of the message at which time the mail
910 program typed EOT.  The
911 .I jobs
912 command will show which commands are suspended.
913 The ^Z should only be typed at the beginning of a line since
914 everything typed on the current line is discarded when a signal is sent
915 from the keyboard.  This also happens on \s-2INTERRUPT\s0, and \s-2QUIT\s0
916 signals.  More information on
917 suspending jobs and controlling them is given in
918 section 2.6.
919 .PP
920 If you write or run programs which are not fully debugged then it may
921 be necessary to stop them somewhat ungracefully.
922 This can be done by sending them a \s-2QUIT\s0
923 signal, sent by typing a ^\e.
924 This will usually provoke the shell to produce a message like:
925 .DS
926 Quit (Core dumped)
927 .DE
928 indicating that a file
929 `core' has been created containing information about the running program's
930 state when it terminated due to the \s-2QUIT\s0 signal.
931 You can examine this file yourself, or forward information to the
932 maintainer of the program telling him/her where the
933 .I "core file"
934 is.
935 .PP
936 If you run background commands (as explained in section 2.6) then these
937 commands will ignore \s-2INTERRUPT\s0 and \s-2QUIT\s0 signals at the
938 terminal.  To stop them you must use the
939 .I kill
940 command.  See section 2.6 for an example.
941 .PP
942 If you want to examine the output of a command without having it move
943 off the screen as the output of the
944 .DS
945 cat /etc/passwd
946 .DE
947 command will, you can use the command
948 .DS
949 more /etc/passwd
950 .DE
951 The
952 .I more
953 program pauses after each complete screenful and types `\-\-More\-\-'
954 at which point you can hit a space to get another screenful, a return
955 to get another line, a `?' to get some help on other commands, or a `q' to end the
956 .I more
957 program.  You can also use more as a filter, i.e.
958 .DS
959 cat /etc/passwd | more
960 .DE
961 works just like the more simple more command above.
962 .PP
963 For stopping output of commands not involving
964 .I more
965 you can use the
966 ^S key to stop the typeout.  The typeout will resume when you
967 hit ^Q or any other key, but ^Q is normally used because
968 it only restarts the output and does not become input to the program
969 which is running.  This works well on low-speed terminals, but at 9600
970 baud it is hard to type ^S and ^Q fast enough to paginate
971 the output nicely, and a program like
972 .I more
973 is usually used.
974 .PP
975 An additional possibility is to use the ^O flush output
976 character; when this character is typed, all output from the current
977 command is thrown away (quickly) until the next input read occurs
978 or until the next shell prompt.  This can be used to allow a command
979 to complete without having to suffer through the output on a slow
980 terminal; ^O is a toggle, so flushing can be turned off by
981 typing ^O again while output is being flushed.
982 .NH 2
983 What now?
984 .PP
985 We have so far seen a number of mechanisms of the shell and learned a lot
986 about the way in which it operates.
987 The remaining sections will go yet further into the internals of the
988 shell, but you will surely want to try using the
989 shell before you go any further.
990 To try it you can log in to \s-2UNIX\s0 and type the following
991 command to the system:
992 .DS
993 chsh myname /bin/csh
994 .DE
995 Here `myname' should be replaced by the name you typed to
996 the system prompt of `login:' to get onto the system.
997 Thus I would use `chsh bill /bin/csh'.
998 .B
999 You only have to do this once; it takes effect at next login.
1000 .R
1001 You are now ready to try using
1002 .I csh.
1003 .PP
1004 Before you do the `chsh' command, the shell you are using when
1005 you log into the system is `/bin/sh'.
1006 In fact, much of the above discussion is applicable to `/bin/sh'.
1007 The next section will introduce many features particular to
1008 .I csh
1009 so you should change your shell to
1010 .I csh
1011 before you begin reading it.
1012 .bp