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