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