BSD 3 development
[unix-history] / usr / doc / cshms
CommitLineData
82a2c00a
BJ
1.RP
2.TL
3An introduction to the C shell
4.br
5\s-2\fI(Revised for the Virtual Vax System)\fP\s0
6.AU
7William Joy
8.AI
9Computer Science Division
10.br
11Department of Electrical Engineering and Computer Science
12.br
13University of California, Berkeley
14.br
15Berkeley, California 94720
16.AB
17.I Csh
18is a new command language interpreter for
19.UX
20systems.
21It incorporates good features of other shells and a
22.I history
23mechanism similar to the
24.I redo
25of \s-2INTERLISP\s0.
26While incorporating many features of other shells which make
27writing shell programs (shell scripts) easier,
28most of the features unique to
29.I csh
30are designed more for the interactive \s-2UNIX\s0 user.
31.PP
32\s-2UNIX\s0
33users who have read a general introduction to the system
34will find a valuable basic explanation of the shell here.
35Simple terminal interaction with
36.I csh
37is possible after reading just the first section of this document.
38The second section describes the shells capabilities which you can
39explore after you have begun to become acquainted with the shell.
40Later sections introduce features which are useful, but not necessary
41for all users of the shell.
42.PP
43Back matter includes an appendix listing special characters of the shell
44and a glossary of terms and commands introduced in this manual.
45.AE
46.SH
47.if n .ND
48Introduction
49.PP
50A
51.I shell
52is a command language interpreter.
53.I Csh
54is the name of one particular command interpreter on
55\s-2UNIX\s0.
56The primary purpose of
57.I csh
58is to translate command lines typed at a terminal into
59system actions, such as invocation of other programs.
60.I Csh
61is a user program just like any you might write.
62Hopefully,
63.I csh
64will be a very useful program for you
65in interacting with the \s-2UNIX\s0 system.
66.PP
67In addition to this document, you will want to refer to a copy
68of the ``\s-2UNIX\s0 Programmers Manual.''
69The
70.I csh
71documentation in the manual provides a full description of all
72features of the shell and is a final reference for questions
73about the shell.
74.PP
75Many words in this document are shown in
76.I italics.
77These are important words;
78names of commands, and words which have special meaning in discussing
79the shell and \s-2UNIX\s0.
80Many of the words are defined in a glossary at the end of this document.
81If you don't know what is meant by a word, you should look
82for it in the glossary.
83.SH
84Acknowledgements
85.PP
86Numerous people have provided good input about previous versions
87of
88.I csh
89and aided in its debugging and in the debugging of its documentation.
90I would especially like to thank Michael Ubell
91who made the crucial observation that history commands could be
92done well over the word structure of input text, and implemented
93a prototype history mechanism in an older version of the shell.
94Eric Allman has also provided a large number of useful comments on the
95shell, helping to unify those concepts which are present and to identify
96and eliminate useless and marginally useful features.
97Mike O'Brien suggested the pathname hashing
98mechanism, to speed command execution; this suggestion lead to the
99.I cshsave
100mechanism which can be used to speed shell startup.
101.br
102.bp
103.NH
104Terminal usage of the shell
105.NH 2
106The basic notion of commands
107.PP
108A
109.I shell
110in
111\s-2UNIX\s0
112acts mostly as a medium through which other
113.I commands
114are invoked.
115While it has a set of
116.I builtin
117commands which it performs directly,
118most useful commands are, in fact, external to the shell.
119The shell is thus distinguished from the command interpreters of other
120systems both by the fact that it is just a user program, and by the fact
121that it is used almost exclusively as a mechanism for invoking other programs.
122.PP
123Commands in the \s-2UNIX\s0 system expect a list of strings or
124.I words
125as arguments.
126Thus the command
127.DS
128mail bill
129.DE
130consists of two words.
131The first word
132.I mail
133names the command to be executed, in this case the
134mail program which sends messages to other users.
135The shell uses the name of the command in attempting to run it for you.
136It will look in a number of
137.I directories
138for a file with the name
139.I mail
140which is expected to contain the mail program.
141.PP
142The rest of the words of the command are given to the command itself to execute.
143In this case we specified also the word
144.I bill
145which is interpreted by the
146.I mail
147program to be the name of a user to whom mail is to be sent.
148In normal terminal usage we might use the
149.I mail
150command as follows.
151.DS
152% mail bill
153I have a question about the csh documentation.
154My document seems to be missing page 5.
155Does a page five exist?
156 Bill
157EOT
158%
159.DE
160.PP
161Here we typed a message to send to
162.I bill
163and ended this message with a control-d which sent an end-of-file to
164the mail program.
165The mail program
166then echoed the characters `EOT' and transmitted our message.
167The characters `% ' were printed before and after the mail command
168by the shell to indicate that input was needed.
169.PP
170After typing the `% ' prompt the shell was reading command input from
171our terminal.
172We typed a complete command `mail bill'.
173The shell then executed the
174.I mail
175program with argument
176.I bill
177and went dormant waiting for it to complete.
178The mail program then read input from our terminal until we signalled
179an end-of-file after which the shell noticed that mail had completed
180and signaled us that it was ready to read from the terminal again by
181printing another `% ' prompt.
182.PP
183This is the essential pattern of all interaction with \s-2UNIX\s0
184through the shell.
185A complete command is typed at the terminal, the shell executes
186the command and when this execution completes prompts for a new command.
187If you run the editor for an hour, the shell will patiently wait for
188you to finish editing and obediently prompt you again whenever you finish
189editing.
190.PP
191An example of a useful command you can execute now is the
192.I tset
193command, which sets the default
194.I erase
195and
196.I kill
197characters on your terminal \- the erase character erases the last
198character you typed and the kill character erases the entire line you
199have entered so far.
200By default, the erase character is `#' and the kill character is `@'.
201Most people who use \s-2CRT\s0 displays prefer to use the backspace
202(control-h) character as their erase character since it is then easier
203to see what you have typed so far.
204You can make this be true by typing
205.DS
206tset \-e
207.DE
208which tells the program
209.I tset
210to set the erase character, and its default setting for this character
211is a backspace.
212.NH 2
213Flag arguments
214.PP
215A useful notion in \s-2UNIX\s0 is that of a
216.I flag
217argument.
218While many arguments to commands specify file names or user names
219some arguments rather specify an optional capability of the command
220which you wish to invoke.
221By convention, such arguments begin with the character `\-'.
222Thus the command
223.DS
224ls
225.DE
226will produce a list of the files in the current directory.
227The option
228.I \-s
229is the size option, and
230.DS
231ls \-s
232.DE
233causes
234.I ls
235to also give, for each file the size of the file in blocks of 512
236characters.
237The manual page for each command in the \s-2UNIX\s0 programmers manual
238gives the available options for each command.
239The
240.I ls
241command has a large number of useful and interesting options.
242Most other commands have either no options or only one or two options.
243It is hard to remember options of commands which are not used very
244frequently, so most \s-2UNIX\s0 utilities perform only one or two functions
245rather than having a large number of hard to remember options.
246.NH 2
247Output to files
248.PP
249Many commands may read input or write output to files rather
250than simply taking input and output from the terminal.
251Each such command could take special words as arguments indicating
252where the output is to go.
253It is simpler, and usually
254sufficient, to connect these commands to files to which they wish to
255write, within the shell itself, and just before they are executed.
256.PP
257Thus suppose we wish to save the current date in a file called `now'.
258The command
259.DS
260date
261.DE
262will print the current date on our terminal.
263This is because our terminal is the default
264.I "standard output"
265for the date command and the date command prints the date on its
266standard output.
267The shell lets us redirect the
268.I "standard output"
269of a command through a
270notation using the
271.I metacharacter
272`>' and the name of the file where output is to be placed.
273Thus the command
274.DS
275date > now
276.DE
277runs the
278.I date
279command in an environment where its standard output is
280the file `now' rather than our terminal.
281Thus this command places the current date and time in the file `now'.
282It is important to know that the
283.I date
284command was unaware that its output was going to a file rather than
285to our terminal.
286The shell performed this
287.I redirection
288before the command began executing.
289.PP
290One other thing to note here is that the file `now'
291need not have existed before the
292.I date
293command was executed; the shell would have created the file if it did
294not exist.
295And if the file did exist?
296If it had existed previously these previous contents would have been discarded!
297A shell option
298.I noclobber
299exists to prevent this from happening accidentally;
300it is discussed in section 2.2.
301.PP
302The system normally keeps files which you create with `>' and all other files.
303Thus the default is for files to be permanent. If you wish to create a file
304which will be removed automatically, you can begin its name with a `#'
305character, this `scratch' character denotes the fact that the file will
306be a scratch file.*
307.FS
308*Note that if your erase character is a `#', you will have to precede the
309`#' with a `\e'. The fact that the `#' character is the old (pre-\s-2CRT\s0)
310standard erase character means that it seldom appears in a file name, and
311allows this convention to be used for scratch files. If you are using a
312\s-2CRT\s0, your erase character should be a control-h, as we demonstrated
313in section 1.1 how this could be set up.
314.FE
315The system will remove such files after a couple of days,
316or sooner if file space becomes very tight.
317Thus, in running the
318.I date
319command above, we don't really want to save the output forever, so we
320would more likely do
321.DS
322date > #now
323.DE
324.NH 2
325Metacharacters in the shell
326.PP
327The shell has a large number of
328special characters (like `>')
329which indicate special functions.
330We say that these notations have
331.I syntactic
332and
333.I semantic
334meaning to the shell.
335In general, most characters which are neither letters nor digits
336have special meaning to the shell.
337We shall shortly learn a means of
338.I quotation
339which allows us to create words which contain
340.I metacharacters
341and to thus work without constantly worrying about whether certain
342characters are metacharacters.
343.PP
344Note that the shell is only reading input when it has prompted with
345`% '.
346Thus metacharacters will normally have effect only then.
347We need not worry about placing shell metacharacters in a letter
348we are sending via
349.I mail.
350.NH 2
351Input from files; pipelines
352.PP
353We learned above how to route the standard output of a command
354to a file.
355It is also possible to route the standard input of a command from a file.
356This is not often necessary since most commands will read from
357a file name given as argument.
358We can give the command
359.DS
360sort < data
361.DE
362to run the
363.I sort
364command with standard input, where the command normally
365reads, from the file
366`data'.
367We would more likely say
368.DS
369sort data
370.DE
371letting the
372.I sort
373command open the file
374`data'
375for input itself since this is less to type.
376.PP
377We should note that if we just typed
378.DS
379sort
380.DE
381then the sort program would sort lines from its
382.I "standard input."
383Since we did not
384.I redirect
385the standard input, it would sort lines as we typed them on the terminal
386until we typed a control-d to generate an end-of-file.
387.PP
388A most useful capability is the ability to combine the standard output
389of one command with the standard input of the next, i.e. to run the
390commands in a sequence known as a
391.I pipeline.
392For instance the command
393.DS
394ls \-s
395.DE
396normally produces a list of the files in our directory with the size
397of each in blocks of 512 characters.
398If we are interested in learning which of our files is largest we
399may wish to have this sorted by size rather than by name, which is
400the default way in which
401.I ls
402sorts.
403We could look at the many options of
404.I ls
405to see if there was an option to do this but would eventually discover
406that there is not.
407Instead we can use a couple of simple options of the
408.I sort
409command, combining it with
410.I ls
411to get what we want.
412.PP
413The
414.I \-n
415option of sort specifies a numeric sort rather than an alphabetic sort.
416Thus
417.DS
418ls \-s | sort \-n
419.DE
420specifies that the output of the
421.I ls
422command run with the option
423.I \-s
424is to be
425.I piped
426to the command
427.I sort
428run with the numeric sort option.
429This would give us a sorted list of our files by size, but with the
430smallest first.
431We could then use the
432.I \-r
433reverse sort option and the
434.I head
435command in combination with the previous command doing
436.DS
437ls \-s | sort \-n \-r | head \-5
438.DE
439Here we have taken a list of our files sorted alphabetically,
440each with the size in blocks.
441We have run this to the standard input of the
442.I sort
443command asking it to sort numerically in reverse order (largest first).
444This output has then been run into the command
445.I head
446which gives us the first few lines out.
447In this case we have asked
448.I head
449for the first 5 lines.
450Thus this command gives us the names and sizes of our 5 largest files.
451.PP
452The metanotation introduced above is called the
453.I pipe
454mechanism.
455Commands separated by `\||\|' characters are connected together by the
456shell and the output of each is run into the input of the next.
457The leftmost command in a pipeline will normally take its standard
458input from the terminal and the rightmost will place its standard
459output on the terminal.
460Other examples of pipelines will be given later when we discuss the
461history mechanism;
462one important use of pipes which is illustrated there is in the
463routing of information to the line printer.
464.NH 2
465Filenames
466.PP
467Many commands to be executed will need the names of files as arguments.
468\s-2UNIX\s0 pathnames consist of a number of components separated by `/'.
469Each component except the last names a directory in which the next
470component resides.
471Thus the pathname
472.DS
473/etc/motd
474.DE
475specifies a file in the directory
476`etc'
477which is a subdirectory of the
478.I root
479directory `/'.
480Within this directory the file named is `motd' which stands
481for `message of the day'.
482Filenames which do not begin with `/' are interpreted starting at
483the current
484.I working
485directory.
486This directory is, by default, your
487.I home
488directory and can be changed dynamically by the
489.I chdir
490change directory command.
491.PP
492Most filenames consist of a number of alphanumeric characters and `.'s.
493In fact, all printing characters except `/' may appear in filenames.
494It is inconvenient to have most non-alphabetic characters in filenames
495because many of these have special meaning to the shell.
496The character `.' is not a shell-metacharacter and is often used as
497the prefix with an
498.I extension
499of a base name.
500Thus
501.DS
502prog.c prog.o prog.errs prog.output
503.DE
504are four related files.
505They share a
506.I root
507portion of a name
508(a root portion being that part of the name that is left when a trailing
509`.' and following characters which are not `.' are stripped off).
510The file
511`prog.c'
512might be the source for a C program,
513the file `prog.o' the corresponding object file,
514the file
515`prog.errs' the errors resulting from a compilation of the program
516and the file
517`prog.output' the output of a run of the program.
518.PP
519If we wished to refer to all four of these files in a command, we could
520use the metanotation
521.DS
522prog.*
523.DE
524This word is expanded by the shell, before the command to which it is
525an argument is executed, into a list of names which begin with `prog.'.
526The character `*' here matches any sequence (including the empty sequence)
527of characters in a file name.
528The names which match are sorted into the argument list to the command
529alphabetically.
530Thus the command
531.DS
532echo prog.*
533.DE
534will echo the names
535.DS
536prog.c prog.errs prog.o prog.output
537.DE
538Note that the names are in lexicographic order here, and a different
539order than we listed them above.
540The
541.I echo
542command receives four words as arguments, even though we only typed
543one word as as argument directly.
544The four words were generated by filename expansion of the metasyntax
545in the one input word.
546.PP
547Other metanotations for
548.I "filename expansion"
549are also available.
550The character `?' matches any single character in a filename.
551Thus
552.DS
553echo ? \|?? \|???
554.DE
555will echo a line of filenames; first those with one character names,
556then those with two character names, and finally those with three
557character names.
558The names of each length will be independently lexicographically sorted.
559.PP
560Another mechanism consists of a sequence of characters between `[' and `]'.
561This metasequence matches any single character from the enclosed set.
562Thus
563.DS
564prog.[co]
565.DE
566will match
567.DS
568prog.c prog.o
569.DE
570in the example above.
571We can also place two characters astride a `\-' in this notation to denote
572a range.
573Thus
574.DS
575chap.[1\-5]
576.DE
577might match files
578.DS
579chap.1 chap.2 chap.3 chap.4 chap.5
580.DE
581if they existed.
582This is shorthand for
583.DS
584chap.[12345]
585.DE
586and otherwise equivalent.
587.PP
588An important point to note is that if a list of argument words to
589a command (an
590.I "argument list)"
591contains filename expansion syntax, and if this filename expansion syntax
592fails to match any existing file names, then the shell considers this
593to be an error and prints a diagnostic
594.DS
595No match.
596.DE
597.PP
598Another very important point is that the character `.' at the beginning
599of a filename is treated specially.
600Neither `*' or `?' or the `[' `]' mechanism will match it.
601This prevents accidental matching of the filenames `.' and `..'
602in the current directory which have special meaning to the system,
603as well as other files such as
604.I \&.cshrc
605which are not normally
606visible.
607We will discuss the special role of the file
608.I \&.cshrc
609later.
610.PP
611Another filename expansion mechanism gives access to the pathname of
612the
613.I home
614directory of other users.
615This notation consists of the character `~' followed by another users
616login name.
617For instance the word `~bill' would map to the pathname `/mnt/bill'
618if the home directory for `bill' was in the directory `/mnt/bill'.
619Since, on large systems, users may have login directories scattered over
620many different disk volumes with different prefix directory names,
621this notation provides a reliable way of accessing the files
622of other users.
623.PP
624A special case of this notation consists of a `~' alone, e.g. `~/mbox'.
625This notation is expanded by the shell into the file `mbox' in your
626.I home
627directory, i.e. into `/mnt/bill/mbox' for me on the Cory Hall \s-2UNIX\s0
628system.
629This can be very useful if you have used
630.I chdir
631to change to another users directory and have found a file you wish to
632copy using
633.I cp.
634You can do
635.DS
636cp thatfile ~
637.DE
638which will be expanded by the shell to
639.DS
640cp thatfile /mnt/bill
641.DE
642e.g., which the copy command will interpret as a request to make a copy of
643`thatfile'
644in the directory `/mnt/bill'.
645The `~' notation doesn't, by itself, force named files to exist.
646This is useful, for example, when using the
647.I cp
648command,
649e.g.
650.DS
651cp thatfile ~/saveit
652.DE
653.PP
654There also exists a mechanism using the characters `{' and `}' for
655abbreviating a set of word which have common parts but cannot
656be abbreviated by the above mechanisms because they are not files,
657are the names of files which do not yet exist,
658are not thus conveniently described.
659This mechanism will be described much later,
660in section 4.1,
661as it is used much less frequently.
662.NH 2
663Quotation
664.PP
665We have already seen a number of metacharacters used by the shell.
666These metacharacter pose a problem in that we cannot use them directly
667as parts of words.
668Thus the command
669.DS
670echo *
671.DE
672will not echo the character `*'.
673It will either echo an sorted list of filenames in the
674current directory, or print the message `No match' if there are
675no files in the current directory.
676.PP
677The recommended mechanism for placing characters which are neither numbers,
678digits, `/', `.' or `\-' in an argument word to a command is to enclose
679it with single quotation characters `\'', i.e.
680.DS
681echo \'*\'
682.DE
683There is one special character `!' which is used by the
684.I history
685mechanism of the shell and which cannot be
686.I escaped
687in this way.
688It and the character `\'' itself can be preceded by a single `\e'
689to prevent their special meaning.
690These two mechanisms suffice to place any printing character into a word
691which is an argument to a shell command.
692.NH 2
693Terminating commands
694.PP
695When you are running a command from the shell and the shell is
696dormant waiting for it to complete there are a couple of ways in
697which you can force such a command to complete.
698For instance if you type the command
699.DS
700cat /etc/passwd
701.DE
702the system will print a copy of a list of all users of the system
703on your terminal.
704This is likely to continue for several minutes unless you stop it.
705You can send an
706\s-2INTERRUPT\s0
707signal to the
708.I cat
709command by hitting the
710\s-2DEL\s0 or \s-2RUBOUT\s0
711key on your terminal.
712Actually, hitting this key sends this
713\s-2INTERRUPT\s0
714signal to all programs running on your terminal, including your shell.
715The shell normally ignores such signals however, so that the only
716program affected by the
717\s-2INTERRUPT\s0
718will be
719.I cat.
720Since
721.I cat
722does not take any precautions to catch this signal
723the
724\s-2INTERRUPT\s0
725will cause it to terminate.
726The shell notices that
727.I cat
728has died and prompts you again with `% '.
729If you hit \s-2INTERRUPT\s0 again, the shell will just
730repeat its prompt since it catches \s-2INTERRUPT\s0 signals
731and chooses to continue to execute commands rather than going away
732like
733.I cat
734did, which would have the effect of logging you out.
735.PP
736Another way in which many programs terminate is when they get an end-of-file
737from their standard input.
738Thus the
739.I mail
740program in the first example above was terminated when we hit a control-d
741which generates and end-of-file from the standard input.
742The shell also terminates when it gets an end-of-file printing `logout';
743\s-2UNIX\s0 then logs you off the system.
744Since this means that typing too many control-d's can accidentally log us off,
745the shell has a mechanism for preventing this.
746This
747.I ignoreeof
748option will be discussed in section 2.2.
749.PP
750If a command has its standard input redirected from a file, then it will
751normally terminate when it reaches the end of this file.
752Thus if we execute
753.DS
754mail bill < prepared.text
755.DE
756the mail command will terminate without our typing a control-d.
757This is because it read to the end-of-file of our file
758`prepared.text' in which we placed a message for `bill' with an editor.
759We could also have done
760.DS
761cat prepared.text \||\| mail bill
762.DE
763since the
764.I cat
765command would then have written the text through the pipe to the
766standard input of the mail command.
767When the
768.I cat
769command completed it would have terminated,
770closing down the pipeline
771and the
772.I mail
773command would have received an end-of-file from it and terminated.
774Using a pipe here is more complicated than redirecting input
775so we would more likely use the first form.
776These commands could also have been stopped by sending an \s-2INTERRUPT\s0.
777.PP
778If you write or run programs which are not fully debugged then it may
779be necessary to stop them somewhat ungracefully.
780This can be done by sending them a \s-2QUIT\s0
781signal, generated by a control-\e.
782This will usually provoke the shell to produce a message like:
783.DS
784a.out: Quit \-\- Core dumped
785.DE
786indicating that a file
787`core' has been created containing information about the program `a.out's
788state when it ran amuck.
789You can examine this file yourself, or forward information to the
790maintainer of the program telling him/her where the
791.I "core file"
792is.
793.PP
794If you run background commands (as explained in section 2.6) then these
795commands will ignore \s-2INTERRUPT\s0 and \s-2QUIT\s0 signals at the
796terminal. To stop them you must use the
797.I kill
798program. See section 2.6 for an example.
799.NH 2
800What now?
801.PP
802We have so far seen a number of mechanisms of the shell and learned a lot
803about the way in which it operates.
804The remaining sections will go yet further into the internals of the
805shell, but you will surely want to try using the shell before you go any further.
806To try it you can log in to \s-2UNIX\s0 and type the following
807command to the system:
808.DS
809chsh myname /bin/csh
810.DE
811Here
812`myname'
813should be replaced by the name you typed to
814the system prompt of
815`login:' to get onto the system.
816Thus I would use `chsh bill /bin/csh'.
817.B
818You only have to do this once; it takes effect at next login.
819.R
820You are now ready to try using
821.I csh.
822.PP
823Before you do the `chsh' command, the shell you are using when
824you log into the system is `/bin/sh'.
825In fact, much of the above discussion is applicable to `/bin/sh'.
826The next section will introduce many features particular to
827.I csh
828so you should change your shell to
829.I csh
830before you begin reading it.
831.bp
832.NH
833Details on the shell for terminal users
834.NH 2
835Shell startup and termination
836.PP
837When you login, the shell is placed by the system in your
838.I home
839directory and begins by reading commands from a file
840.I \&.cshrc
841in this directory.
842All shells which you may create during your terminal session will
843read from this file.
844We will later see what kinds of commands are usefully placed there.
845For now we need not have this file and the shell does not complain about
846its absence.
847.PP
848A
849.I login
850shell, executed after you login to the system,
851will, after it reads commands from
852.I \&.cshrc,
853read commands from a file
854.I \&.login
855also in your home directory.
856This file contains commands which you wish to do each time you login
857to the \s-2UNIX\s0 system.
858My
859.I \&.login
860file looks something like:
861.DS
862tset \-d adm3a \-p adm3a
863fixexrc
864set history=20
865set time=3
866.DE
867on the \s-2CORY\s0 Hall \s-2UNIX\s0 system.
868This file contains four commands to be executed by \s-2UNIX\s0
869each time I login.
870The first is a
871.I tset
872command which informs the system that I usually dial in on a Lear-Siegler
873\s-2ADM\-3A\s0 terminal and that if I am on a patchboard port on the
874fifth floor of Evans Hall I am probably also on an \s-2ADM\-3A\s0.
875The second command is a
876.I fixexrc
877which manipulates my
878.I ex
879startup file
880in certain ways if I am on a dialup port.
881We need not be concerned with exactly what this command does.
882In general you may have certain commands in your
883.I \&.login
884which are particular to you.
885.PP
886The next two
887.I set
888commands are interpreted directly by the shell and affect the values
889of certain shell variables to modify the future behavior of the shell.
890Setting the variable
891.I time
892tells the shell to print time statistics on commands which take more
893than a certain threshold of machine time (in this case 3 \s-2CPU\s0
894seconds).
895Setting the variable
896.I history
897tells the shell how much history of previous command words it should
898save in case I wish to repeat or rerun modified versions of previous
899commands.
900Since there is a certain overhead in this mechanism the shell does
901not set this variable by default, but rather lets users who wish to
902use the mechanism set it themselves.
903The value of 20 is a reasonably large value to assign to
904.I history.
905More casual users of the
906.I history
907mechanism
908would probably set a value of 5 or 10.
909The use of the
910.I history
911mechanism will be described subsequently.
912.PP
913After executing commands from
914.I \&.login
915the shell reads commands from your terminal, prompting for each with
916`% '.
917When it receives an end-of-file from the terminal, the shell
918will print `logout' and execute commands from the file `.logout'
919in your home directory.
920After that the shell will die and \s-2UNIX\s0 will log you off the system.
921If the system is not going down, you will receive a new login message.
922In any case, after the `logout' message the shell is doomed
923and will take no further input from the terminal.
924.NH 2
925Shell variables
926.PP
927The shell maintains a set of
928.I variables.
929We saw above the variables
930.I history
931and
932.I time
933which had values `20' and `3'.
934In fact, each shell variable has as value an array of
935zero or more
936.I strings.
937Shell variables may be assigned values by the set command. It has
938several forms, the most useful of which was given above and is
939.DS
940set name=value
941.DE
942.PP
943Shell variables may be used to store values which are to
944be reintroduced into commands later through a substitution mechanism.
945The shell variables most commonly referenced are, however, those which the
946shell itself refers to.
947By changing the values of these variables one can directly affect the
948behavior of the shell.
949.PP
950One of the most important variables is the variable
951.I path.
952This variable contains a sequence of directory names where the shell
953searches for commands.
954The
955.I set
956command
957shows the value of all variables currently defined (we usually say
958.I set)
959in the shell.
960The default value for path will be shown by
961.I set
962to be
963.DS
964% set
965argv
966home /mnt/bill
967path (. /bin /usr/bin)
968prompt %
969shell /bin/csh
970status 0
971%
972.DE
973This notation indicates that the variable path points to the current
974directory `.' and then `/bin' and `/usr/bin'.
975Commands which you may write might be in `.' (usually one of
976your directories).
977The most heavily used system commands live in `/bin'.
978Less heavily used system commands live in `/usr/bin'.
979.PP
980A number of new programs on the system live in the directory
981`/usr/new'.
982If we wish, as well we might, all shells which we invoke to have
983access to these new programs we can place the command
984.DS
985set path=(. /usr/new /bin /usr/bin)
986.DE
987in our file
988.I \&.cshrc
989in our home directory.
990Try doing this and then logging out and back in and do
991.DS
992set
993.DE
994again to see that the value assigned to
995.I path
996has changed.
997.PP
998Other useful built in variables are the variable
999.I home
1000which shows your home directory,
1001the variable
1002.I ignoreeof
1003which can be set in your
1004.I \&.login
1005file to tell the shell not to exit when it receives an end-of-file from
1006a terminal.
1007To logout from \s-2UNIX\s0
1008with
1009.I ignoreeof
1010set you must type
1011.DS
1012logout
1013.DE
1014This is one of several variables which the shell does not care about the
1015value of, only whether they are
1016.I set
1017or
1018.I unset.
1019Thus to set this variable you simply do
1020.DS
1021set ignoreeof
1022.DE
1023and to unset it do
1024.DS
1025unset ignoreeof
1026.DE
1027Both
1028.I set
1029and
1030.I unset
1031are built-in commands of the shell.
1032.PP
1033Finally, some other built-in shell variables of use are the
1034variables
1035.I noclobber
1036and
1037.I mail.
1038The metasyntax
1039.DS
1040> filename
1041.DE
1042which redirects the output of a command
1043will overwrite and destroy the previous contents of the named file.
1044In this way you may accidentally overwrite a file which is valuable.
1045If you would prefer that the shell not overwrite files in this
1046way you can
1047.DS
1048set noclobber
1049.DE
1050in your
1051.I \&.login
1052file.
1053Then trying to do
1054.DS
1055date > now
1056.DE
1057would cause a diagnostic if `now' existed already.
1058You could type
1059.DS
1060date >! now
1061.DE
1062if you really wanted to overwrite the contents of `now'.
1063The `>!' is a special metasyntax indicating that clobbering the
1064file is ok.
1065.PP
1066If you receive mail frequently while you are logged in and wish to
1067be informed of the arrival of this mail you can put a command
1068.DS
1069set mail=/usr/mail/yourname
1070.DE
1071in your
1072.I \&.login
1073file.
1074Here you should change `yourname' to your login name.
1075The shell will look at this file every 10 minutes to see if new mail has arrived.
1076If you receive mail only infrequently you are better off not
1077setting this variable. In this case it will only serve to delay the shells
1078response to you when it checks for mail.
1079.PP
1080The use of shell variables to introduce text into commands, which is
1081most useful in shell command scripts, will be introduced in section 2.4.
1082.NH 2
1083The shell's history list
1084.PP
1085The shell can maintain a history list into which it places the words
1086of previous commands.
1087It is possible to use a metanotation to reintroduce commands or words
1088from commands in forming new commands.
1089This mechanism can be used to repeat previous commands or to
1090correct minor typing mistakes in commands.
1091.PP
1092Consider the following transcript:
1093.DS
1094% where michael
1095michael is on tty0 dialup 300 baud 642-7927
1096% write !$
1097write michael
1098Long time no see michael.
1099Why don't you call me at 524-4510.
1100EOF
1101%
1102.DE
1103Here we asked the system where
1104.I michael
1105was logged in.
1106It told us he was on `tty0'
1107and we told the shell to invoke a `write' command to
1108`!$'.
1109This is a history notation which means the last word of the last
1110command executed, in this case `michael'.
1111The shell performed this substitution and then echoed the command
1112as it would execute it.
1113Let us assume that we don't hear anything from michael.
1114We might do
1115.DS
1116% ps t0
1117 PID TTY TIME COMMAND
1118 4808 0 0:05 \-
1119% !!
1120ps t0
1121 PID TTY TIME COMMAND
1122 5104 0 0:00 \- 7
1123% !where
1124where michael
1125michael is not logged in
1126%
1127.DE
1128Here we ran a
1129.I ps
1130on the teletype
1131.I michael
1132was logged in on to see that he had a shell.
1133Repeating this command via the history substitution `!!'
1134we saw that he had logged out and that only a
1135.I getty
1136process was running on his terminal.
1137Repeating the
1138.I where
1139command
1140showed that he was indeed gone, most likely having
1141hung up the phone in order to be able to call.
1142.PP
1143This illustrates several useful features of the history mechanism.
1144The form `!!' repeats the last command execution.
1145The form `!string' repeats the last command which began with
1146a word of which `string' is a prefix.
1147Another useful command form is `\(ualhs\(uarhs' performing a substitute
1148similar to that in
1149.I ed
1150or
1151.I ex.
1152Thus after
1153.DS
1154% cat ~bill/csh/sh..c
1155/mnt/bill/csh/sh..c: No such file or directory
1156% \(ua..(ua.
1157cat ~bill/csh/sh.c
1158#include "sh.h"
1159
1160/*
1161 * C Shell
1162 *
1163 * Bill Joy, UC Berkeley
1164 * October, 1978
1165 */
1166
1167char *pathlist[] = { SRCHP
1168%
1169.DE
1170here we used the substitution to correct a typing mistake,
1171and then rubbed the command out after we saw that we had found the
1172file that we wanted.
1173The substitution changed the two `.' characters to a single `.'
1174character.
1175.PP
1176After this command we might do
1177.DS
1178% !! \||\| lpr
1179cat ~bill/csh/sh.c \||\| lpr
1180.DE
1181to put a copy of this file on the line printer, or (immediately
1182after the
1183.I cat
1184which worked above)
1185.DS
1186% pr !$ \||\| lpr
1187pr ~bill/csh/sh.c \||\| lpr
1188%
1189.DE
1190to print a copy on the printer using
1191.I pr.
1192.PP
1193More advanced forms of the history mechanism are also possible.
1194A notion of modification on substitutions allows one to say
1195(after the first successful
1196.I cat
1197above).
1198.DS
1199% cd !$:h
1200cd ~bill/csh
1201%
1202.DE
1203The trailing `:h' on the history substitution here causes only
1204the head portion of the pathname reintroduced by the history
1205mechanism to be substituted.
1206This mechanism and related mechanisms are used less often than
1207the forms above.
1208.PP
1209A complete description of history mechanism
1210features is given in the C shell manual pages in the \s-2UNIX\s0 Programmers Manual.
1211.NH 2
1212Aliases
1213.PP
1214The shell has an
1215.I alias
1216mechanism which can be used to make transformations on input commands.
1217This mechanism can be used to simplify the commands you type,
1218to supply default arguments to commands,
1219or to perform transformations on commands and their arguments.
1220The alias facility is similar to the macro facility of many assemblers.
1221.PP
1222Some of the features obtained by aliasing can be obtained also
1223using shell command files, but these take place in another instance
1224of the shell and cannot directly affect the current shells environment
1225and commands such as
1226.I chdir
1227which must be done in the current shell.
1228.PP
1229As an example, suppose that there is a new version of the mail program
1230on the system called `Mail'
1231you wish to use, rather than the standard mail program which is called `mail'.
1232If you place the shell command
1233.DS
1234alias mail Mail
1235.DE
1236in your
1237.I \&.login
1238file, the shell will transform an input line of the form
1239.DS
1240mail bill
1241.DE
1242into a call on `Mail'.
1243More generally, suppose we wish the command `ls' to always show
1244sizes of files, that is to always do `\-s'.
1245We can do
1246.DS
1247alias ls ls \-s
1248.DE
1249or even
1250.DS
1251alias dir ls \-s
1252.DE
1253creating a new command syntax `dir'
1254which does an `ls \-s'.
1255If we say
1256.DS
1257dir ~bill
1258.DE
1259then the shell will translate this to
1260.DS
1261ls \-s /mnt/bill
1262.DE
1263.PP
1264Thus the
1265.I alias
1266mechanism can be used to provide short names for commands,
1267to provide default arguments,
1268and to define new short commands in terms of other commands.
1269It is also possible to define aliases which contain multiple
1270commands or pipelines, showing where the arguments to the original
1271command are to be substituted using the facilities of the
1272history mechanism.
1273Thus the definition
1274.DS
1275alias cd \'cd \e!* ; ls \'
1276.DE
1277would do an
1278.I ls
1279command after each change directory
1280.I cd
1281command.
1282We enclosed the entire alias definition in `\'' characters to prevent
1283most substitutions from occuring and the character `;' from being
1284recognized as a parser metacharacter.
1285The `!' here is escaped with a `\e' to prevent it from being interpreted
1286when the alias command is typed in.
1287The `\e!*' here substitutes the entire argument list to the pre-aliasing
1288.I cd
1289command, without giving an error if there were no arguments.
1290The `;' separating commands is used here
1291to indicate that one command is to be done and then the next.
1292Similarly the definition
1293.DS
1294alias whois \'grep \e!\(ua /etc/passwd\'
1295.DE
1296defines a command which looks up its first argument in the password file.
1297.NH 2
1298Detached commands; >> and >& redirection
1299.PP
1300There are a few more metanotations useful to the terminal user
1301which have not been introduced yet.
1302The metacharacter `&' may be placed after a command, or after a sequence
1303of commands separated by `;' or `|'.
1304This causes the shell to not wait for the commands to terminate before
1305prompting again.
1306We say that they are
1307.I detached
1308or
1309.I background
1310processes. Thus
1311.DS
1312% pr ~bill/csh/sh.c \||\| lpr &
13135120
13145121
1315%
1316.DE
1317Here the shell printed two numbers and came back very quickly rather
1318than waiting for the
1319.I pr
1320and
1321.I lpr
1322commands to finish.
1323These numbers are the process numbers assigned by the system to the
1324.I pr
1325and
1326.I lpr
1327commands.\(dg
1328.FS
1329\(dgRunning commands in the background like this tends to slow down
1330the system and is not a good idea if the system is overloaded.
1331When overloaded, the system will just bog down more if you run a large
1332number of processes at once.
1333.FE
1334.PP
1335Since havoc would result if a command run in the background were to
1336read from your terminal at the same time as the shell does, the
1337default standard input for a command run in the background is
1338not your terminal, but an empty file called `/dev/null'.
1339Commands run in the background are also made immune to
1340\s-2INTERRUPT\s0 and \s-2QUIT\s0 signals which you may subsequently
1341generate at your terminal.*
1342.FS
1343*If a background command stops suddenly when you hit \s-2INTERRUPT\s0
1344or \s-2QUIT\s0 it is likely a bug in the background program.
1345.FE
1346.PP
1347If you intend to log off the system before the command completes you
1348must run the command immune to
1349\s-2HANGUP\s0
1350signals.
1351This is done by placing the word
1352`nohup' before each program in the command, i.e.:
1353.DS
1354nohup man csh \||\| nohup lpr &
1355.DE
1356.PP
1357In addition to the standard output, commands also have a
1358diagnostic output
1359which is normally directed to the terminal even when the standard output
1360is directed to a file or a pipe.
1361It is occasionally desirable to direct the diagnostic output along with
1362the standard output.
1363For instance if you want to redirect the output of a long running command
1364into a file and wish to have a record of any error diagnostic it produces
1365you can do
1366.DS
1367command >& file
1368.DE
1369The `>&' here tells the shell to route both the diagnostic output and the
1370standard output into `file'.
1371of the standard output.
1372Similarly you can give the command
1373.DS
1374command |\|& lpr
1375.DE
1376to route both standard and diagnostic output through the pipe
1377to the line printer daemon
1378.I lpr.#
1379.FS
1380#A command form
1381.DS
1382command >&! file
1383.DE
1384exists, and is used when
1385.I noclobber
1386is set and
1387.I file
1388already exists.
1389.FE
1390.PP
1391Finally, it is possible to use the form
1392.DS
1393command >> file
1394.DE
1395to place output at the end of an existing file.\(dg
1396.FS
1397\(dgIf
1398.I noclobber
1399is set, then an error will result if
1400.I file
1401does not exist, otherwise the shell will create
1402.I file
1403if it doesn't exist.
1404A form
1405.DS
1406command >>! file
1407.DE
1408makes it not be an error for file to not exist when
1409.I noclobber
1410is set.
1411.FE
1412.NH 2
1413Useful built-in commands
1414.PP
1415We now give a few of the useful built-in commands of the shell describing
1416how they are used.
1417.PP
1418The
1419.I alias
1420command described above is used to assign new aliases and to show the
1421existing aliases.
1422With no arguments it prints the current aliases.
1423It may also be given an argument such as
1424.DS
1425alias ls
1426.DE
1427to show the current alias for, e.g., `ls'.
1428.PP
1429The
1430.I cd
1431and
1432.I chdir
1433commands are equivalent, and change the working directory of the shell.
1434It is useful to make a directory for each project you wish to work on
1435and to place all files related to that project in that directory.
1436Thus after you login you can do
1437.DS
1438% pwd
1439/mnt/bill
1440% mkdir newpaper
1441% chdir newpaper
1442% pwd
1443/mnt/bill/newpaper
1444%
1445.DE
1446after which you will be in the directory
1447.I newpaper.
1448You can place a group of related files there.
1449You can return to your `home' login directory by doing just
1450.DS
1451chdir
1452.DE
1453with no arguments.
1454We used the
1455.I pwd
1456print working directory command to show the name of the current
1457directory here.
1458The current directory will usually be a subdirectory of your
1459home directory, and have it (here `/mnt/bill') at the start of it.
1460.PP
1461The
1462.I echo
1463command prints its arguments.
1464It is often used in shell scripts or as an interactive command
1465to see what filename expansions will yield.
1466.PP
1467The
1468.I history
1469command will show the contents of the history list.
1470The numbers given with the history events can be used to reference
1471previous events which are difficult to reference using the
1472contextual mechanisms introduced above.
1473There is also a shell variable called
1474.I prompt.
1475By placing a `!' character in its value the shell will there substitute
1476the index of the current command in the history list.
1477You can use this number to refer to this command in a history substitution.
1478Thus you could
1479.DS
1480set prompt=\'\e! % \'
1481.DE
1482Note that the `!' character had to be escaped here even within `\'' characters.
1483.PP
1484The
1485.I logout
1486command can be used to terminate a login shell which has
1487.I ignoreeof
1488set.
1489.PP
1490The
1491.I repeat
1492command can be used to repeat a command several times.
1493Thus to make 5 copies of the file
1494.I one
1495in the file
1496.I five
1497you could do
1498.DS
1499repeat 5 cat one >> five
1500.DE
1501.PP
1502The
1503.I setenv
1504command can be used, on version 7 \s-2UNIX\s0 systems,
1505to set variables in the environment.
1506Thus
1507.DS
1508setenv TERM adm3a
1509.DE
1510will set the value of the environment variable \s-2TERM\s0
1511to
1512`adm3a'.
1513A user program
1514.I printenv
1515exists which will print out the environment.
1516It might then show:
1517.DS
1518% printenv
1519HOME /usr/bill
1520SHELL /bin/csh
1521TERM adm3a
1522%
1523.DE
1524.PP
1525The
1526.I source
1527command can be used to force the current shell to read commands from
1528a file.
1529Thus
1530.DS
1531source .cshrc
1532.DE
1533can be used after editing in a change to the
1534.I \&.cshrc
1535file which you wish to take effect before the next time you login.
1536.PP
1537The
1538.I time
1539command can be used to cause a command to be timed no matter how much
1540\s-2CPU\s0 time it takes.
1541Thus
1542.DS
1543% time cp five five.save
15440.0u 0.3s 0:01 26%
1545% time wc five.save
1546 1200 6300 37650 five.save
15471.2u 0.5s 0:03 55%
1548%
1549.DE
1550indicates that the
1551.I cp
1552command used less that 1/10th of a second of user time and only
15533/10th of a second of system time in copying the file `five' to
1554`five.save'.
1555The command word count
1556`wc'
1557on the other hand used 1.2 seconds of user time and 0.5 seconds of system
1558time in 3 seconds of elapsed time in counting the number of words,
1559character and lines in `five.save'.
1560The percentage `55%' indicates that over this period of 3 seconds,
1561our command `wc' used an average of 55 percent of the available \s-2CPU\s0
1562cycles of the machine.
1563This is a very high percentage and indicates that the system is lightly
1564loaded.
1565.PP
1566The
1567.I unalias
1568and
1569.I unset
1570commands can be used
1571to remove aliases and variable definitions from the shell.
1572.PP
1573The
1574.I wait
1575command can be used after starting processes with `&'
1576to quickly see if they have finished.
1577If the shell responds immediately with another prompt, they have.
1578Otherwise you can wait for the shell to prompt at which point they
1579will have finished, or interrupt the shell by sending a \s-2RUB\s0
1580or \s-2DELETE\s0 character.
1581If the shell is interrupted, it will print the names and numbers of the
1582processes it knows to be unfinished.
1583Thus:
1584.DS
1585% nroff paper \||\| lpr &
15862450
15872451
1588% wait
1589 2451 lpr
1590 2450 nroff
1591wait: Interrupted.
1592%
1593.DE
1594.PP
1595You can check again later by doing another
1596.I wait,
1597or see which commands are still running by doing a
1598.I ps.
1599As `time'
1600will show you,
1601.I ps
1602is fairly expensive.
1603It is thus counterproductive to run many
1604.I ps
1605commands to see how a background process is doing.\(dg
1606.FS
1607\(dgIf you do you are usurping with these
1608.I ps
1609commands the processor time the job needs to finish, thereby delaying its
1610completion!
1611.FE
1612.PP
1613If you run a background process and decide you want to stop it for whatever
1614reason you must use the
1615.I kill
1616program.
1617You must use the number of the processes you wish to kill.
1618Thus to stop the
1619.I nroff
1620in the above pipeline you would do
1621.DS
1622% kill 2450
1623% wait
16242450: nroff: Terminated.
1625%
1626.DE
1627Here the shell printed a diagnostic that we terminated `nroff' only
1628after we did a
1629.I wait.
1630If we want the shell to discover the termination of all processes
1631it has created we must, in general, use
1632.I wait.
1633.NH 2
1634What else?
1635.PP
1636This concludes the basic discussion of the shell for terminal users.
1637There are more features of the shell to be discussed here, and all
1638features of the shell are discussed in its manual pages.
1639One useful feature which is discussed later is the
1640.I foreach
1641built-in command which can be used to run the same command
1642sequence with a number of different arguments.
1643.PP
1644If you intend to use \s-2UNIX\s0 a lot you you should look through
1645the rest of this document and the shell manual pages to become familiar
1646with the other facilities which are available to you.
1647.bp
1648.NH
1649Shell control structures and command scripts
1650.NH 2
1651Introduction
1652.PP
1653It is possible to place commands in files and to cause shells to be
1654invoked to read and execute commands from these files,
1655which are called
1656.I "shell scripts."
1657We here detail those features of the shell useful to the writers of such
1658scripts.
1659.NH 2
1660Make
1661.PP
1662It is important to first note what shell scripts are
1663.I not
1664useful for.
1665There is a program called
1666.I make
1667which is very useful for maintaining a group of related files
1668or performing sets of operations on related files.
1669For instance a large program consisting of one or more files
1670can have its dependencies described in a
1671.I makefile
1672which contains definitions of the commands used to create these
1673different files when changes occur.
1674Definitions of the means for printing listings, cleaning up the directory
1675in which the files reside, and installing the resultant programs
1676are easily, and most appropriately placed in this
1677.I makefile.
1678This format is superior and preferable to maintaining a group of shell
1679procedures to maintain these files.
1680.PP
1681Similarly when working on a document a
1682.I makefile
1683may be created which defines how different versions of the document
1684are to be created and which options of
1685.I nroff
1686or
1687.I troff
1688are appropriate.
1689.NH 2
1690Invocation and the argv variable
1691.PP
1692A
1693.I csh
1694command script may be interpreted by saying
1695.DS
1696% csh script ...
1697.DE
1698where
1699.I script
1700is the name of the file containing a group of
1701.I csh
1702commands and
1703`\&...' is replaced by a sequence of arguments.
1704The shell places these arguments in the variable
1705.I argv
1706and then begins to read commands from the script.
1707These parameters are then available through the same mechanisms
1708which are used to reference any other shell variables.
1709.PP
1710If you make the file
1711`script'
1712executable by doing
1713.DS
1714chmod 755 script
1715.DE
1716and place a shell comment at the beginning of the shell script
1717(i.e. begin the file with a `#' character)
1718then a `/bin/csh' will automatically be invoked to execute `script' when
1719you type
1720.DS
1721script
1722.DE
1723If the file does not begin with a `#' then the standard shell
1724`/bin/sh' will be used to execute it.
1725This allows you to convert your older shell scripts to use
1726.I csh
1727at your convenience.
1728.NH 2
1729Variable substitution
1730.PP
1731After each input line is broken into words and history substitutions
1732are done on it, the input line is parsed into distinct commands.
1733Before each command is executed a mechanism know as
1734.I "variable substitution"
1735is done on these words.
1736Keyed by the character `$' this substitution replaces the names
1737of variables by their values.
1738Thus
1739.DS
1740echo $argv
1741.DE
1742when placed in a command script would cause the current value of the
1743variable
1744.I argv
1745to be echoed to the output of the shell script.
1746It is an error for
1747.I argv
1748to be unset at this point.
1749.PP
1750A number of notations are provided for accessing components and attributes
1751of variables.
1752The notation
1753.DS
1754$?name
1755.DE
1756expands to `1' if name is
1757.I set
1758or to `0'
1759if name is not
1760.I set.
1761It is the fundamental mechanism used for checking whether particular
1762variables have been assigned values.
1763All other forms of reference to undefined variables cause errors.
1764.PP
1765The notation
1766.DS
1767$#name
1768.DE
1769expands to the number of elements in the variable
1770.I name.
1771Thus
1772.DS
1773% set argv=(a b c)
1774% echo $?argv
17751
1776% echo $#argv
17773
1778% unset argv
1779% echo $?argv
17800
1781% echo $argv
1782Undefined variable: argv.
1783%
1784.DE
1785.PP
1786It is also possible to access the components of a variable
1787which has several values.
1788Thus
1789.DS
1790$argv[1]
1791.DE
1792gives the first component of
1793.I argv
1794or in the example above `a'.
1795Similarly
1796.DS
1797$argv[$#argv]
1798.DE
1799would give `c',
1800and
1801.DS
1802$argv[1\-2]
1803.DE
1804Other notations useful in shell scripts are
1805.DS
1806$\fIn\fR
1807.DE
1808where
1809.I n
1810is an integer as a shorthand for
1811.DS
1812$argv[\fIn\fR\|]
1813.DE
1814the
1815.I n\|th
1816parameter and
1817.DS
1818$*
1819.DE
1820which is a shorthand for
1821.DS
1822$argv
1823.DE
1824The form
1825.DS
1826$$
1827.DE
1828expands to the process number of the current shell.
1829Since this process number is unique in the system it can
1830be used in generation of unique temporary file names.
1831.PP
1832One minor difference between `$\fIn\fR\|' and `$argv[\fIn\fR\|]'
1833should be noted here.
1834The form
1835`$argv[\fIn\fR\|]'
1836will yield an error if
1837.I n
1838is not in the range
1839`1\-$#argv'
1840while `$n'
1841will never yield an out of range subscript error.
1842This is for compatibility with the way older shells handled parameters.
1843.PP
1844Another important point is that it is never an error to give a subrange
1845of the form `n\-'; if there are less than
1846.I n
1847components of the given variable then no words are substituted.
1848A range of the form `m\-n' likewise returns an empty vector without giving
1849an error when \fIm\fR exceeds the number of elements of the given variable,
1850provided the subscript \fIn\fR is in range.
1851.NH 2
1852Expressions
1853.PP
1854In order for interesting shell scripts to be constructed it
1855must be possible to evaluate expressions in the shell based on the
1856values of variables.
1857In fact, all the arithmetic operations of the language C are available
1858in the shell
1859with the same precedence that they have in C.
1860In particular, the operations `==' and `!=' compare strings
1861and the operators `&&' and `|\|\||' implement the boolean and/or operations.
1862.PP
1863The shell also allows file enquiries of the form
1864.DS
1865\-? filename
1866.DE
1867where `?' is replace by a number of single characters.
1868For instance the expression primitive
1869.DS
1870\-e filename
1871.DE
1872tell whether the file
1873`filename'
1874exists.
1875Other primitives test for read, write and execute access to the file,
1876whether it is a directory, or has non-zero length.
1877.PP
1878It is possible to test whether a command terminates normally,
1879by a primitive of the
1880form `{ command }' which returns true, i.e. `1' if the command
1881succeeds exiting normally with exit status 0, or `0' if the command
1882terminates abnormally or with exit status non-zero.
1883If more detailed information about the execution status of a command
1884is required, it can be executed and the variable `$status' examined
1885in the next command.
1886Since `$status' is set by every command, it is very transient.
1887It can be saved if it is inconvenient to use it only in the single
1888immediately following command.
1889.PP
1890For a full list of expression components available see the manual
1891section for the shell.
1892.NH 2
1893Sample shell script
1894.PP
1895A sample shell script which makes use of the expression mechanism
1896of the shell and some of its control structure follows:
1897.DS
1898% cat copyc
1899#
1900# Copyc copies those C programs in the specified list
1901# to the directory ~/backup if they differ from the files
1902# already in ~/backup
1903#
1904set noglob
1905foreach i ($argv)
1906
1907 if ($i:r.c != $i) continue # not a .c file so do nothing
1908
1909 if (! \-r ~/backup/$i:t) then
1910 echo $i:t not in backup... not cp\e\'ed
1911 continue
1912 endif
1913
1914 cmp \-s $i ~/backup/$i:t # to set $status
1915
1916 if ($status != 0) then
1917 echo new backup of $i
1918 cp $i ~/backup/$i:t
1919 endif
1920end
1921.DE
1922.PP
1923This script makes use of the
1924.I foreach
1925command, which causes the shell to execute the commands between the
1926.I foreach
1927and the matching
1928.I end
1929for each of the values given between `(' and `)' with the named
1930variable, in this case `i' set to successive values in the list.
1931Within this loop we may use the command
1932.I break
1933to stop executing the loop
1934and
1935.I continue
1936to prematurely terminate one iteration
1937and begin the next.
1938After the
1939.I foreach
1940loop the iteration variable
1941(\fIi\fR in this case)
1942has the value at the last iteration.
1943.PP
1944We set the variable
1945.I noglob
1946here to prevent filename expansion of the members of
1947.I argv.
1948This is a good idea, in general, if the arguments to a shell script
1949are filenames which have already been expanded or if the arguments
1950may contain filename expansion metacharacters.
1951It is also possible to quote each use of a `$' variable expansion,
1952but this is harder and less reliable.
1953.PP
1954The other control construct used here is a statement of the form
1955.DS
1956\fBif\fR ( expression ) \fBthen\fR
1957 command
1958 ...
1959\fBendif\fR
1960.DE
1961The placement of the keywords here is
1962.B not
1963flexible due to the current implementation of the shell.\(dg
1964.FS
1965\(dgThe following two formats are not currently acceptable to the shell:
1966.DS
1967\fBif\fR ( expression ) # \fBWon't work!\fR
1968\fBthen\fR
1969 command
1970 ...
1971\fBendif\fR
1972.DE
1973and
1974.DS
1975\fBif\fR ( expression ) \fBthen\fR command \fBendif\fR # \fBWon't work\fR
1976.DE
1977.FE
1978.PP
1979The shell does have another form of the if statement of the form
1980.DS
1981\fBif\fR ( expression ) \fBcommand\fR
1982.DE
1983which can be written
1984.DS
1985\fBif\fR ( expression ) \e
1986 command
1987.DE
1988Here we have escaped the newline for the sake of appearance,
1989and the `\e' must \fBimmediately\fR.
1990The command must not involve `\||\|', `&' or `;'
1991and must not be another control command.
1992The second form requires the final `\e' to
1993.B immediately
1994precede the end-of-line.
1995.PP
1996The more general
1997.I if
1998statements above also admit a sequence of
1999.I else\-if
2000pairs followed by a single
2001.I else
2002and an
2003.I endif,
2004e.g.:
2005.DS
2006\fBif\fR ( expression ) \fBthen\fR
2007 commands
2008\fBelse\fR \fBif\fR (expression ) \fBthen\fR
2009 commands
2010\&...
2011
2012\fBelse\fR
2013 commands
2014\fBendif\fR
2015.DE
2016.PP
2017Another important mechanism used in shell scripts is `:' modifiers.
2018We can use the modifier `:r' here to extract a root of a filename.
2019Thus if the variable
2020.I i
2021has the value
2022`foo.bar'
2023then
2024.DS
2025% echo $i $i:r
2026foo.bar foo
2027%
2028.DE
2029shows how the `:r' modifier strips off the trailing `.bar'.
2030Other modifiers will take off the last component of a pathname leaving
2031the head `:h' or all but the last component of a pathname leaving the
2032tail `:t'.
2033These modifiers are fully described in the
2034.I csh
2035manual pages in the programmers manual.
2036It is also possible to use the
2037.I "command substitution"
2038mechanism described in the next major section to perform modifications
2039on strings to then reenter the shells environment.
2040Since each usage of this mechanism involves the creation of a new process,
2041it is much more expensive to use than the `:' modification mechanism.#
2042.FS
2043#It is also important to note that
2044the current implementation of the shell limits the number of `:' modifiers
2045on a `$' substitution to 1.
2046Thus
2047.DS
2048% echo $i $i:h:t
2049/a/b/c /a/b:t
2050%
2051.DE
2052does not do what one would expect.
2053.FE
2054Finally, we note that the character `#' lexically introduces a shell
2055comment in shell scripts (but not from the terminal).
2056All subsequent characters on the input line after a `#' are discarded
2057by the shell.
2058This character can be quoted using `\'' or `\e' to place it in
2059an argument word.
2060.NH 2
2061Other control structures
2062.PP
2063The shell also has control structures
2064.I while
2065and
2066.I switch
2067similar to those of C.
2068These take the forms
2069.DS
2070\fBwhile\fR ( expression )
2071 commands
2072\fBend\fR
2073.DE
2074and
2075.DS
2076\fBswitch\fR ( word )
2077
2078\fBcase\fR str1:
2079 commands
2080 \fBbreaksw\fR
2081
2082\& ...
2083
2084\fBcase\fR strn:
2085 commands
2086 \fBbreaksw\fR
2087
2088\fBdefault:\fR
2089 commands
2090 \fBbreaksw\fR
2091
2092\fBendsw\fR
2093.DE
2094For details see the manual section for
2095.I csh.
2096C programmers should note that we use
2097.I breaksw
2098to exit from a
2099.I switch
2100while
2101.I break
2102exits a
2103.I while
2104or
2105.I foreach
2106loop.
2107A common mistake to make in
2108.I csh
2109scripts is to use
2110.I break
2111rather than
2112.I breaksw
2113in switches.
2114.PP
2115Finally,
2116.I csh
2117allows a
2118.I goto
2119statement, with labels looking like they do in C, i.e.:
2120.DS
2121loop:
2122 commands
2123 \fBgoto\fR loop
2124.DE
2125.NH 2
2126Supplying input to commands
2127.PP
2128Commands run from shell scripts receive by default the standard
2129input of the shell which is running the script.
2130This it is different from previous shells running
2131under \s-2UNIX\s0. It allowing shell scripts to fully participate
2132in pipelines, but mandates extra notation for commands which are to take
2133inline data.
2134.PP
2135Thus we need a metanotation for supplying inline data to commands in
2136shell scripts.
2137As an example, consider this script which runs the editor to
2138delete leading blanks from the lines in each argument file
2139.DS
2140% cat deblank
2141# deblank \-\- remove leading blanks
2142foreach i ($argv)
2143ed \- $i << \'EOF\'
21441,$s/\(ua[ ]*//
2145w
2146q
2147\&\'EOF\'
2148end
2149%
2150.DE
2151The notation `<< \'EOF\''
2152means that the standard input for the
2153.I ed
2154command is to come from the text in the shell script file
2155up to the next line consisting of exactly `\'EOF\''.
2156The fact that the `EOF' is enclosed in `\'' characters, i.e. quoted,
2157causes the shell to not perform variable substitution on the
2158intervening lines.
2159In general, if any part of the word following the `<<' which the
2160shell uses to terminate the text to be given to the command is quoted
2161then these substitutions will not be performed.
2162In this case since we used the form `1,$' in our editor script
2163we needed to insure that this `$' was not variable substituted.
2164We could also have insured this by preceding the `$' here with a `\e',
2165i.e.:
2166.DS
21671,\e$s/\(ua[ ]*//
2168.DE
2169but quoting the `EOF' terminator is a more reliable way of achieving the
2170same thing.
2171.NH 2
2172Catching interrupts
2173.PP
2174If our shell script creates temporary files, we may wish to catch
2175interruptions of the shell script so that we can clean up
2176these files.
2177We can then do
2178.DS
2179onintr label
2180.DE
2181where
2182.I label
2183is a label in our program.
2184If an interrupt is received the shell will do a
2185`goto label'
2186and we can remove the temporary files and then do a
2187.I exit
2188command (which is built in to the shell)
2189to exit from the shell script.
2190If we wish to exit with a non-zero status we can do
2191.DS
2192exit(1)
2193.DE
2194e.g. to exit with status `1'.
2195.NH 2
2196What else?
2197.PP
2198There are other features of the shell useful to writers of shell
2199procedures.
2200The
2201.I verbose
2202and
2203.I echo
2204options and the related
2205.I \-v
2206and
2207.I \-x
2208command line options can be used to help trace the actions of the shell.
2209The
2210.I \-n
2211option causes the shell only to read commands and not to execute
2212them and may sometimes be of use.
2213.PP
2214One other thing to note is that
2215.I csh
2216will not execute shell scripts which do not begin with the
2217character `#', that is shell scripts that do not begin with a comment.
2218Similarly, the `/bin/sh' on your system may well defer to `csh'
2219to interpret shell scripts which begin with `#'.
2220This allows shell scripts for both shells to live in harmony.
2221.PP
2222There is also another quotation mechanism using `"' which allows
2223only some of the expansion mechanisms we have so far discussed to occur
2224on the quoted string and serves to make this string into a single word
2225as `\'' does.
2226.bp
2227.NH 1
2228Miscellaneous, less generally useful, shell mechanisms
2229.NH 2
2230Loops at the terminal; variables as vectors
2231.PP
2232It is occasionally useful to use the
2233.I foreach
2234control structure at the terminal to aid in performing a number
2235of similar commands.
2236For instance, there were at one point three shells in use on the Cory \s-2UNIX\s0
2237system at Cory Hall,
2238`/bin/sh',
2239`/bin/nsh',
2240and
2241`/bin/csh'.
2242To count the number of persons using each shell one could issue the commands
2243.DS
2244% grep \-c csh$ /etc/passwd
224527
2246% grep \-c nsh$ /etc/passwd
2247128
2248% grep \-c \-v sh$ /etc/passwd
2249430
2250%
2251.DE
2252Since these commands are very similar we can use
2253.I foreach
2254to do this more easily.
2255.DS
2256% foreach i (\'sh$\' \'csh$\' \'\-v sh$\')
2257? grep \-c $i /etc/passwd
2258? end
225927
2260128
2261430
2262%
2263.DE
2264Note here that the shell prompts for
2265input with `? ' when reading the body of the loop.
2266.PP
2267Very useful with loops are variables which contain lists of filenames
2268or other words.
2269You can, for example, do
2270.DS
2271% set a=(`ls`)
2272% echo $a
2273csh.n csh.rm
2274% ls
2275csh.n
2276csh.rm
2277% echo $#a
22782
2279%
2280.DE
2281The
2282.I set
2283command here gave the variable
2284.I a
2285a list of all the filenames in the current directory as value.
2286We can then iterate over these names to perform any chosen function.
2287.PP
2288The output of a command within `\`' characters is converted by
2289the shell to a list of words.
2290You can also place the `\`' quoted string within `"' characters
2291to take each (non-empty) line as a component of the variable;
2292preventing the lines from being split into words at blanks and tabs.
2293A modifier `:x' exists which can be used later to expand each component
2294of the variable into another variable splitting it into separate words
2295at embedded blanks and tabs.
2296.NH 2
2297Braces { ... } in argument expansion
2298.PP
2299Another form of filename expansion, alluded
2300to before involves the characters `{' and `}'.
2301These characters specify that the contained strings, separated by `,'
2302are to be consecutively substituted into the containing characters
2303and the results expanded left to right.
2304Thus
2305.DS
2306A{str1,str2,...strn}B
2307.DE
2308expands to
2309.DS
2310Astr1B Astr2B ... AstrnB
2311.DE
2312This expansion occurs before the other filename expansions, and may
2313be applied recursively (i.e. nested).
2314The results of each expanded string are sorted separately, left
2315to right order being preserved.
2316The resulting filenames are not required to exist if no other expansion
2317mechanisms are used.
2318This means that this mechanism can be used to generate arguments which are
2319not filenames, but which have common parts.
2320.PP
2321A typical use of this would be
2322.DS
2323mkdir ~/{hdrs,retrofit,csh}
2324.DE
2325to make subdirectories `hdrs', `retrofit' and `csh'
2326in your home directory.
2327This mechanism is most useful when the common prefix is longer
2328than in this example, i.e.
2329.DS
2330chown bin /usr/{bin/{ex,edit},lib/{ex1.1strings,how_ex}}
2331.DE
2332.NH 2
2333Command substitution
2334.PP
2335A command enclosed in `\`' characters is replaced, just before
2336filenames are expanded, by the output from that command.
2337Thus it is possible to do
2338.DS
2339set pwd=\`pwd\`
2340.DE
2341to save the current directory in the variable
2342.I pwd
2343or to do
2344.DS
2345ex \`grep -l TRACE *.c\`
2346.DE
2347to run the editor
2348.I ex
2349suppling as arguments those files whose names end in `.c'
2350which have the string `TRACE' in them.*
2351.FS
2352*Command expansion also occurs in input redirected with `<<'
2353and within `"' quotations.
2354Refer to the shell manual section for full details.
2355.FE
2356.NH 2
2357Other details not covered here
2358.PP
2359In particular circumstances it may be necessary to know the exact
2360nature and order of different substitutions performed by the shell.
2361The exact meaning of certain combinations of quotations is also
2362occasionally important.
2363These are detailed fully in its manual section.
2364.PP
2365The shell has a number of command line option flags mostly of use
2366in writing \s-2UNIX\s0 programs,
2367and debugging shell scripts.
2368See the shells manual section for a list of these options.
2369.bp
2370.SH
2371Appendix \- Special characters
2372.LP
2373The following table lists the special characters of
2374.I csh
2375and the \s-2UNIX\s0 system, giving for each the section(s) in which it
2376is discussed.
2377A number of these characters also have special meaning in expressions.
2378See the
2379.I csh
2380manual section
2381for a complete list.
2382.LP
2383Syntactic metacharacters
2384.DS
2385; 2.4 separates commands to be executed sequentially
2386| 1.5 separates commands in a pipeline
2387( ) 2.2,3.6 brackets expressions and variable values
2388& 2.5 follows commands to be executed without waiting for completion
2389.DE
2390.LP
2391Filename metacharacters
2392.DS
2393/ 1.6 separates components of a file's pathname
2394\. 1.6 separates root parts of a file name from extensions
2395? 1.6 expansion character matching any single character
2396* 1.6 expansion character matching any sequence of characters
2397[ ] 1.6 expansion sequence matching any single character from a set
2398~ 1.6 used at the beginning of a filename to indicate home directories
2399{ } 4.2 used to specify groups of arguments with common parts
2400.DE
2401.LP
2402Quotation metacharacters
2403.DS
2404\e 1.7 prevents meta-meaning of following single character
2405\' 1.7 prevents meta-meaning of a group of characters
2406" 4.3 like \', but allows variable and command expansion
2407.DE
2408.LP
2409Input/output metacharacters
2410.DS
2411< 1.3 indicates redirected input
2412> 1.5 indicates redirected output
2413.DE
2414.LP
2415Expansion/substitution metacharacters
2416.DS
2417$ 3.4 indicates variable substitution
2418! 2.3 indicates history substitution
2419: 3.6 precedes substitution modifiers
2420\(ua 2.3 used in special forms of history substitution
2421\` 4.3 indicates command substitution
2422.DE
2423.LP
2424Other metacharacters
2425.DS
2426# 3.6 begins a shell comment
2427\- 1.2 prefixes option (flag) arguments to commands
2428.DE
2429.bp
2430.SH
2431Glossary
2432.PP
2433This glossary lists the most important terms introduced in the
2434introduction to the
2435shell and gives references to sections of the shell
2436document for further information about them.
2437References of the form
2438`pr (1)'
2439indicate that the command
2440.I pr
2441is in the \s-2UNIX\s0 programmers manual in section 1.
2442You can get an online copy of its manual page by doing
2443.DS
2444man 1 pr
2445.DE
2446References of the form (2.5)
2447indicate that more information can be found in section 2.5 of this
2448manual.
2449.IP \&\fB.\fR 15n
2450Your current directory has the name `.' as well as the name printed
2451by the command
2452.I pwd.
2453The current directory `.' is usually the first component of the search
2454path contained in the variable
2455.I path,
2456thus commands which are in `.' are found first (2.2).
2457The character `.' is also used in separating components of filenames
2458(1.6).
2459The character `.' at the beginning of a component of a pathname is
2460treated specially and not matched by the filename expansion
2461metacharacters `?', `*', and `[' `]' pairs (1.6).
2462.IP \&\fB..\fR
2463Each directory has a file `..' in it which is a reference to its
2464.I parent
2465directory.
2466After changing into the directory with
2467.I chdir,
2468i.e.
2469.DS
2470chdir paper
2471.DE
2472you can return to the parent directory by doing
2473.DS
2474chdir ..
2475.DE
2476The current directory is printed by
2477.I pwd
2478(2.6).
2479.IP alias
2480An
2481.I alias
2482specifies a shorter or different name for a \s-2UNIX\s0
2483command, or a transformation on a command to be performed in
2484the shell.
2485The shell has a
2486command
2487.I alias
2488which establishes aliases and can print their current values.
2489The command
2490.I unalias
2491is used to remove aliases (2.6).
2492.IP argument
2493Commands in \s-2UNIX\s0 receive a list of argument words.
2494Thus the command
2495.DS
2496echo a b c
2497.DE
2498consists of a command name `echo' and three argument words `a', `b' and `c' (1.1).
2499.IP argv
2500The list of arguments to a command written in the shell language
2501(a shell script or shell procedure) is stored in a variable called
2502.I argv
2503within the shell.
2504This name is taken from the conventional name in the
2505C programming language (3.4).
2506.IP background
2507Commands started without waiting for them to complete are called
2508.I background
2509commands (1.5).
2510.IP bin
2511A directory containing binaries of programs and shell scripts to be
2512executed is typically called a `bin' directory.
2513The standard system `bin' directories are `/bin' containing the most
2514heavily used commands and `/usr/bin' which contains most other user
2515programs.
2516Other binaries are contained in directories such as `/usr/new' where
2517new programs are placed.
2518You can place binaries in any directory.
2519If you wish to execute them often, the name of the directories
2520should be a component of the variable
2521.I path.
2522.IP break
2523.I Break
2524is a built-in command used to exit from loops within the control
2525structure of the shell (3.6).
2526.IP builtin
2527A command executed directly by the shell is called a
2528.I builtin
2529command.
2530Most commands in \s-2UNIX\s0 are not built into the shell,
2531but rather exist as files in `bin' directories.
2532These commands are accessible because the directories in which
2533they reside are named in the
2534.I path
2535variable.
2536.IP case
2537A
2538.I case
2539command is used as a label in a
2540.I switch
2541statement in the shells control structure, similar to that of the
2542language C.
2543Details are given in the shells documentation `csh (NEW)' (3.7).
2544.IP cat
2545The
2546.I cat
2547program catenates a list of specified files on the standard output.
2548It is usually used to look at the contents of a single file on the terminal,
2549to `cat a file' (1.8, 2.3).
2550.IP cd
2551The
2552.I cd
2553command is used to change the working directory.
2554With no arguments,
2555.I cd
2556changes your working directory to be your
2557.I home
2558directory (2.3) (2.6).
2559.IP chdir
2560The
2561.I chdir
2562command is a synonym for
2563.I cd.
2564.I Cd
2565is usually used because it is easier to type.
2566.IP chsh
2567The
2568.I chsh
2569command is used to change the shell which you use on \s-2UNIX\s0.
2570By default, you use an older `standard' version of the shell
2571which resides in `/bin/sh'.
2572You can change your shell to `/bin/csh' by doing
2573.DS
2574chsh your-login-name /bin/csh
2575.DE
2576Thus I would do
2577.DS
2578chsh bill /bin/csh
2579.DE
2580It is only necessary to do this once.
2581The next time you log in to \s-2UNIX\s0 after doing this command,
2582you will be using
2583.I csh
2584rather than the shell in `/bin/sh' (1.9).
2585.IP cmp
2586.I Cmp
2587is a program which compares files.
2588It is usually used on binary files, or to see if two files are identical (3.6).
2589For comparing text files the program
2590.I diff,
2591described in `diff (1)' is used.
2592.IP command
2593A function performed by the system, either by the shell
2594(a builtin command) or by a program residing in a file in
2595a directory within the \s-2UNIX\s0 system is called a
2596.I command
2597(1.1).
2598.IP "command substitution"
2599.br
2600The replacement of a command enclosed in `\`' characters
2601by the text output by that command
2602is called
2603.I "command substitution"
2604(3.6, 4.3).
2605.IP component
2606A part of a
2607.I pathname
2608between `/' characters is called a
2609.I component
2610of that pathname.
2611A
2612.I variable
2613which has multiple strings as value is said to have
2614several
2615.I components,
2616each string is a
2617.I component
2618of the variable.
2619.IP continue
2620A builtin command which causes execution of the enclosing
2621.I foreach
2622or
2623.I while
2624loop to cycle prematurely.
2625Similar to the
2626.I continue
2627command in the programming language C (3.6).
2628.IP "core dump"
2629When a program terminates abnormally, the system places an image
2630of its current state in a file named `core'.
2631This `core dump' can be examined with the system debuggers `db (1)'
2632and `cdb (1)' in order to determine what went wrong with the program (1.8).
2633If the shell produces a message of the form:
2634.DS
2635commandname: Illegal instruction \-\- Core dumped
2636.DE
2637(where `Illegal instruction' is only one of several possible
2638messages) you should report this to the author of the program
2639and save the `core' file.
2640If this was a system program you should report this with the
2641.I trouble
2642command `trouble (1)'.
2643.IP cp
2644The
2645.I cp
2646(copy) program is used to copy the contents of one file into another
2647file.
2648It is one of the most commonly used \s-2UNIX\s0 commands (2.6).
2649.IP \&.cshrc
2650The file
2651.I \&.cshrc
2652in your
2653.I home
2654directory is read by each shell as it begins execution.
2655It is usually used to change the setting of the variable
2656.I path
2657and to set
2658.I alias
2659parameters which are to take effect globally (2.1).
2660.IP date
2661The
2662.I date
2663command prints the current date and time (1.3).
2664.IP debugging
2665.I Debugging
2666is the process of correcting mistakes in programs and shell scripts.
2667The shell has several options and variables which may be used
2668to aid in shell debugging (4.4).
2669.IP default
2670The label
2671.I default:
2672is used within shell
2673.I switch
2674statements, as it is in the C language
2675to label the code to be executed if none of the
2676.I case
2677labels matches the value switched on (3.7).
2678.IP \s-2DELETE\s0
2679The
2680\s-2DELETE\s0
2681or
2682\s-2RUBOUT\s0
2683key on the terminal is used to generate an
2684\s-2INTERRUPT\s0
2685signal in \s0UNIX\s0
2686which stops the execution of most programs (2.6).
2687.IP detached
2688A command run without waiting for it to complete is said to be detached
2689(2.5).
2690.IP diagnostic
2691An error message produced by a program is often referred to as a
2692.I diagnostic.
2693Most error messages are not written to the standard output,
2694since that is often directed away from the terminal (1.3, 1.5).
2695Error messsages are instead written to the
2696.I "diagnostic output"
2697which may be directed away from the terminal, but usually is not.
2698Thus diagnostics will usually appear on the terminal (2.5).
2699.IP directory
2700A structure which contains files.
2701At any time you are in one particular directory whose
2702names can be printed by the command `pwd'.
2703The
2704.I chdir
2705command will change you to another directory, and make the files
2706in that directory visible.
2707The directory in which you are when you first login is your
2708.I home
2709directory (1.1, 1.6).
2710.IP echo
2711The
2712.I echo
2713command prints its arguments (1.6, 2.6, 3.6, 3.10).
2714.IP else
2715The
2716.I else
2717command is part of the `if-then-else-endif' control
2718command construct (3.6).
2719.IP \s-2EOF\s0
2720An
2721.I "end-of-file"
2722is generated by the terminal by a control-d,
2723and whenever a command reads to the end of a file which
2724it has been given as input.
2725Commands receiving input from a
2726.I pipe
2727receive an end-of-file when the command sending them
2728input completes.
2729Most commands terminate when they receive an end-of-file.
2730The shell has an option to ignore end-of-file from a terminal
2731input which may help you keep from logging out accidentally
2732by typing too many control-d's (1.1, 1.8, 3.8).
2733.IP escape
2734A character \e used to prevent the special meaning of a metacharacter
2735is said to
2736.I escape
2737the character from its special meaning.
2738Thus
2739.DS
2740echo \e*
2741.DE
2742will echo the character `*' while just
2743.DS
2744echo *
2745.DE
2746will echo the names of the file in the current directory.
2747In this example, \e
2748.I escapes
2749`*' (1.7).
2750There is also a non-printing character called
2751.I escape,
2752usually labelled
2753\s-2ESC\s0
2754or
2755\s-2ALTMODE\s0
2756on terminal keyboards.
2757Some \s-2UNIX\s0 systems use this character to indicate that
2758output is to be suspended.
2759Other systems use control-s.
2760.IP /etc/passwd
2761This file contains information about the accounts currently on the
2762system.
2763If consists of a line for each account with fields separated by
2764`:' characters (2.3).
2765You can look at this file by saying
2766.DS
2767cat /etc/passwd
2768.DE
2769The command
2770.I grep
2771is often used to search for information in this file.
2772See `passwd (5)' and `grep (1)' for more details.
2773.IP exit
2774The
2775.I exit
2776command is used to force termination of a shell script,
2777and is built into the shell (3.9).
2778.IP "exit status"
2779A command which discovers a problem may reflect this back to the command
2780(such as a shell) which invoked (executed) it.
2781It does this by returning a non-zero number as its
2782.I "exit status,"
2783a status of zero being considered
2784`normal termination'.
2785The
2786.I exit
2787command can be used to force a shell command script to give a non-zero
2788exit status (3.5).
2789.IP expansion
2790The replacement of strings in the shell input which contain metacharacters
2791by other strings is referred to as the process of
2792.I expansion.
2793Thus the replacement of the word `*' by a sorted list of files
2794in the current directory is a `filename expansion'.
2795Similarly the replacement of the characters `!!' by the text of
2796the last command is a `history expansion'.
2797Expansions are also referred to as
2798.I substitutions
2799(1.6, 3.4, 4.2).
2800.IP expressions
2801Expressions are used in the shell
2802to control the conditional structures used in the writing of shell
2803scripts and in calculating values for these scripts.
2804The operators available in shell expressions are those of the language
2805C (3.5).
2806.IP extension
2807Filenames often consist of a
2808.I root
2809name and an
2810.I extension
2811separated by the character `.'.
2812By convention, groups of related files often share the same root name.
2813Thus if `prog.c' were a C program, then the object file for this
2814program would be stored in `prog.o'.
2815Similarly a paper written with the
2816`\-me'
2817nroff macro package might be stored in
2818`paper.me'
2819while a formatted version of this paper might be kept in
2820`paper.out' and a list of spelling errors in
2821`paper.errs' (1.6).
2822.IP filename
2823Each file in \s-2UNIX\s0 has a name consisting of up to 14 characters
2824and not including the character `/' which is used in
2825.I pathname
2826building.
2827Most file names do not begin with the character `.', and contain
2828only letters and digits with perhaps a `.' separating the root
2829portion of the filename from an extension (1.6).
2830.IP "filename expansion"
2831.br
2832Filename expansion uses the metacharacters `*', `?' and `[' and `]'
2833to provide a convenient mechanism for naming files.
2834Using filename expansion it is easy to name all the files in
2835the current directory, or all files which have a common root name.
2836Other filename expansion mechanisms use the metacharacter `~' and allow
2837files in other users directories to be named easily (1.6, 4.2).
2838.IP flag
2839Many \s-2UNIX\s0 commands accept arguments which are not the names
2840of files or other users but are used to modify the action of the commands.
2841These are referred to as
2842.I flag
2843options, and by convention consists of one or more letters preceded by
2844the character `\-' (1.2).
2845Thus the
2846.I ls
2847list file commands has an option
2848`\-s' to list the sizes of files.
2849This is specified
2850.DS
2851ls \-s
2852.DE
2853.IP foreach
2854The
2855.I foreach
2856command is used in shell scripts and at the terminal to specify
2857repitition of a sequence of commands while the value of a certain
2858shell variable ranges through a specified list (3.6, 4.1).
2859.IP getty
2860The
2861.I getty
2862program is part of the system which determines the speed at which
2863your terminal is to run when you first log in.
2864It types the initial system banner and `login:'.
2865When no one is logged in on a terminal a
2866.I ps
2867command shows a command of the form
2868`- 7'
2869where `7' here is often some other single letter or digit.
2870This `7' is an option to the
2871.I getty
2872command, indicating the type of port which it is running on.
2873If you see a
2874.I getty
2875command running on a terminal in the output of
2876.I ps
2877you know that no one is logged in on that terminal (2.3).
2878.IP goto
2879The shell has a command
2880.I goto
2881used in shell scripts to transfer control to a given label (3.7).
2882.IP grep
2883The
2884.I grep
2885command searches through a list of argument files for a specified string.
2886Thus
2887.DS
2888grep bill /etc/passwd
2889.DE
2890will print each line in the file
2891`/etc/passwd'
2892which contains the string `bill'.
2893Actually,
2894.I grep
2895scans for
2896.I "regular expressions"
2897in the sense of the editors
2898`ed (1)' and `ex (1)' (2.3).
2899.I Grep
2900stands for
2901`globally find regular expression and print.'
2902.IP hangup
2903When you hangup a phone line, a \s-2HANGUP\s0 signal
2904is sent to all running processes on your terminal, causing
2905them to terminate execution prematurely. If you wish
2906to start commands to run after you log off a dialup you must
2907use the command
2908.I nohup
2909(2.6).
2910.IP head
2911The
2912.I head
2913command prints the first few lines of one or more files.
2914If you have a bunch of files containing text which you are wondering
2915about it is sometimes is useful to run
2916.I head
2917with these files as arguments.
2918This will usually show enough of what is in these files to let you decide
2919which you are interested in (1.5, 2.3).
2920.IP history
2921The
2922.I history
2923mechanism of the shell allows previous commands to be repeated,
2924possibly after modification to correct typing mistakes or to change
2925the meaning of the command.
2926The shell has a
2927.I "history list"
2928where these commands are kept, and a
2929.I history
2930variable which controls how large this list is (1.7, 2.6).
2931.IP "home directory"
2932Each user has a home directory, which is given in your entry
2933in the password file,
2934.I /etc/passwd.
2935This is the directory which you are placed in when you first log in.
2936The
2937.I cd
2938or
2939.I chdir
2940command with no arguments takes you back to this directory, whose
2941name is recorded in the shell variable
2942.I home.
2943You can also access the home directories of other users in forming
2944filenames using a file expansion notation and the character `~' (1.6).
2945.IP if
2946A conditional command within the shell, the
2947.I if
2948command is used in shell command scripts to make decisions
2949about what course of action to take next (3.6).
2950.IP ignoreeof
2951Normally, your shell will exit, printing
2952`logout'
2953if you type a control-d at a prompt of `% '.
2954This is the way you usually log off the system.
2955You can
2956.I set
2957the
2958.I ignoreeof
2959variable if you wish in your
2960.I \&.login
2961file and then use the command
2962.I logout
2963to logout.
2964This is useful if you sometimes accidentally type too many control-d
2965characters, logging yourself off.
2966If the system is slow, this can waste much time, as it may
2967take a long time to log in again (2.2, 2.6).
2968.IP input
2969Many commands on \s-2UNIX\s0 take information from the terminal or from
2970files which they then act on.
2971This information is called
2972.I input.
2973Commands normally read for input from their
2974.I "standard input"
2975which is, by default, the terminal.
2976This standard input can be redirected from a file using a shell metanotation
2977with the character `<'.
2978Many commands will also read from a file specified as argument.
2979Commands placed in pipelines will read from the output of the previous
2980command in the pipeline.
2981The leftmost command in a pipeline reads from the terminal if
2982you neither redirect its input nor give it a file name to use as
2983standard input.
2984Special mechanisms exist for suppling input to commands in shell
2985scripts (1.2, 1.6, 3.8).
2986.IP interrupt
2987An
2988.I interrupt
2989is a signal to a program that is generated by hitting the
2990\s-2RUBOUT\s0 or \s-2DELETE\s0 key.
2991It causes most programs to stop execution.
2992Certain programs such as the shell and the editors
2993handle an interrupt in special ways, usually by stopping what they
2994are doing and prompting for another command.
2995While the shell is executing another command and waiting for it
2996to finish, the shell does not listen to interrupts.
2997The shell often wakes up when you hit interrupt because many commands
2998die when they receive an interrupt (1.8, 2.6, 3.9).
2999.IP kill
3000A program which terminates processes run without waiting for them to
3001complete. (2.6)
3002.IP \&.login
3003The file
3004.I \&.login
3005in your
3006.I home
3007directory is read by the shell each time you log in to \s-2UNIX\s0
3008and the commands there are executed.
3009There are a number of commands which are usefully placed here
3010especially
3011.I tset
3012commands and
3013.I set
3014commands to the shell itself (2.1).
3015.IP logout
3016The
3017.I logout
3018command causes a login shell to exit.
3019Normally, a login shell will exit when you hit control-d
3020generating an end-of-file, but if you have set
3021.I ignoreeof
3022in you
3023.I \&.login
3024file then this will not work and you must use
3025.I logout
3026to log off the \s-2UNIX\s0 system (2.2).
3027.IP \&.logout
3028When you log off of \s-2UNIX\s0 the shell will execute commands from
3029the file
3030.I \&.logout
3031in your
3032.I home
3033directory after it prints `logout'.
3034.IP lpr
3035The command
3036.I lpr
3037is the line printer daemon.
3038The standard input of
3039.I lpr
3040is spooled and printed on the \s-2UNIX\s0 line printer.
3041You can also give
3042.I lpr
3043a list of filenames as arguments to be printed.
3044It is most common to use
3045.I lpr
3046as the last component of a
3047.I pipeline
3048(2.3).
3049.IP ls
3050The
3051.I ls
3052list files command is one of the most commonly used \s-2UNIX\s0
3053commands.
3054With no argument filenames it prints the names of the files in the
3055current directory.
3056It has a number of useful
3057.I flag
3058arguments, and can also be given the names of directories
3059as arguments, in which case it lists the names of the files in these
3060directories (1.2).
3061.IP mail
3062The
3063.I mail
3064program is used to send and receive messages from other \s-2UNIX\s0
3065users (1.1, 2.2).
3066.IP make
3067The
3068.I make
3069command is used to maintain one or more related files and to
3070organize functions to be performed on these files.
3071In many ways
3072.I make
3073is easier to use, and more helpful
3074than
3075shell command scripts (3.2).
3076.IP makefile
3077The file containing command for
3078.I make
3079is called
3080`makefile' (3.2).
3081.IP manual
3082The `manual' often referred to is the
3083`\s-2UNIX\s0 programmers manual.'
3084It contains a number of sections and a description of each \s-2UNIX\s0
3085program.
3086An online version of the manual is accessible through the
3087.I man
3088command.
3089Its documentation can be obtained online via
3090.DS
3091man man
3092.DE
3093.IP metacharacter
3094Many characters which are neither letters nor digits have special meaning
3095either to the shell or to \s-2UNIX\s0.
3096These characters are called
3097.I metacharacters.
3098If it is necessary to place these characters in arguments to commands
3099without them having their special meaning then they must be
3100.I quoted.
3101An example of a metacharacter is the character `>' which is used
3102to indicate placement of output into a file.
3103For the purposes of the
3104.I history
3105mechanism,
3106most unquoted metacharacters form separate words (1.4).
3107The appendix to this user's manual lists the metacharacters
3108in groups by their function.
3109.IP mkdir
3110The
3111.I mkdir
3112command is used to create a new directory (2.6).
3113.IP modifier
3114Substitutions with the history mechanism, keyed by the character `!'
3115or of variables using the metacharacter `$' are often subjected
3116to modifications, indicated by placing the character `:' after the
3117substitution and following this with the modifier itself.
3118The
3119.I "command substitution"
3120mechanism can also be used to perform modification in a similar way,
3121but this notation is less clear (3.6).
3122.IP noclobber
3123The shell has a variable
3124.I noclobber
3125which may be set in the file
3126.I \&.login
3127to prevent accidental destruction of files by the `>' output redirection
3128metasyntax of the shell (2.2, 2.5).
3129.IP nohup
3130A shell command used to allow background commands to run to completion
3131even if you log off a dialup before they complete. (2.5)
3132.IP nroff
3133The standard text formatter on \s-2UNIX\s0 is the program
3134.I nroff.
3135Using
3136.I nroff
3137and one of the available
3138.I macro
3139packages for it, it is possible to have documents automatically
3140formatted and to prepare them for phototypesetting using the
3141typesetter program
3142.I troff
3143(3.2).
3144.IP onintr
3145The
3146.I onintr
3147command is built into the shell and is used to control the action
3148of a shell command script when an interrupt signal is received (3.9).
3149.IP output
3150Many commands in \s-2UNIX\s0 result in some lines of text which are
3151called their
3152.I output.
3153This output is usually placed on what is known as the
3154.I "standard output"
3155which is normally connected to the users terminal.
3156The shell has a syntax using the metacharacter `>' for redirecting
3157the standard output of a command to a file (1.3).
3158Using the
3159.I pipe
3160mechanism and the metacharacter `|' it is also possible for
3161the standard output of one command to become the standard input of another
3162command (1.5).
3163Certain commands such as the line printer daemon
3164.I lpr
3165do not place their results on the standard output but rather in more
3166useful places such as on the line printer (2.3).
3167Similarly the
3168.I write
3169command places its output on another users terminal rather than its
3170standard output (2.3).
3171Commands also have a
3172.I "diagnostic output"
3173where they write their error messages.
3174Normally these go to the terminal even if the standard output has
3175been sent to a file or another command, but it is possible
3176to direct error diagnostics along with standard output using
3177a special metanotation (2.5).
3178.IP path
3179The shell has a variable
3180.I path
3181which gives the names of the directories in which it searches for
3182the commands which it is given.
3183It always checks first to see if the command it is given is
3184built into the shell.
3185If it is, then it need not search for the command as it can do it internally.
3186If the command is not builtin, then the shell searches for a file
3187with the name given in each of the directories in the
3188.I path
3189variable, left to right.
3190Since the normal definition of the
3191.I path
3192variable is
3193.DS
3194path (. /bin /usr/bin)
3195.DE
3196the shell normally looks in the current directory, and then in
3197the standard system directories `/bin' and `/usr/bin' for the named
3198command (2.2).
3199If the command cannot be found the shell will print an error diagnostic.
3200Scripts of shell commands will be executed using another shell to interpret
3201them if they have `execute' bits set.
3202This is normally true because a command of the form
3203.DS
3204chmod 755 script
3205.DE
3206was executed to turn these execute bits on (3.3).
3207.IP pathname
3208A list of names, separated by `/' characters forms a
3209.I pathname.
3210Each
3211.I component,
3212between successive `/' characters, names a directory
3213in which the next component file resides.
3214Pathnames which begin with the character `/' are interpreted relative
3215to the
3216.I root
3217directory in the filesystem.
3218Other pathnames are interpreted relative to the current directory
3219as reported by
3220.I pwd.
3221The last component of a pathname may name a directory, but
3222usually names a file.
3223.IP pipeline
3224A group of commands which are connected together, the standard
3225output of each connected to the standard input of the next
3226is called a
3227.I pipeline.
3228The
3229.I pipe
3230mechanism used to connect these commands is indicated by
3231the shell metacharacter `|' (1.5, 2.3).
3232.IP pr
3233The
3234.I pr
3235command is used to prepare listings of the contents of files
3236with headers giving the name of the file and the date and
3237time at which the file was last modified (2.3).
3238.IP printenv
3239The
3240.I printenv
3241command is used on version 7 \s-2UNIX\s0 systems
3242to print the current setting of variables in the environment.
3243As of this writing, only the \s-2VAX/UNIX\s0 system on the fifth
3244floor of Evans Hall is running a version 7 \s-2UNIX\s0 system.
3245The other systems are running version 6, which does not have
3246or need
3247.I printenv
3248(2.6).
3249.IP process
3250A instance of a running program is called a process (2.6).
3251The
3252numbers used by
3253.I kill
3254and printed by
3255.I wait
3256are unique numbers generated for these processes by \s-2UNIX\s0.
3257They are useful in
3258.I kill
3259commands which can be used to stop background processes. (2.6)
3260.IP program
3261Usually synonymous with
3262.I command;
3263a binary file or shell command script
3264which performs a useful function is often
3265called a program.
3266.IP "programmers manual"
3267.br
3268Also referred to as the
3269.I manual.
3270See the glossary entry for `manual'.
3271.IP prompt
3272Many programs will print a prompt on the terminal when they expect
3273input.
3274Thus the editor
3275`ex (NEW)' will print a `:' when it expects input.
3276The shell prompts for input with `% ' and occasionally with `? ' when
3277reading commands from the terminal (1.1).
3278The shell has a variable
3279.I prompt
3280which may be set to a different value to change the shells main prompt.
3281This is mostly used when debugging the shell (2.6).
3282.IP ps
3283The
3284.I ps
3285command is used to show the processes you are currently running.
3286Each process is shown with its unique process number,
3287an indication of the terminal name it is attached to,
3288and the amount of \s-2CPU\s0 time it has used so far.
3289The command is identified by printing some of the words used
3290when it was invoked (2.3, 2.6).
3291Login shells, such as the
3292.I csh
3293you get when you login are shown as `\-'.
3294.IP pwd
3295The
3296.I pwd
3297command prints the full pathname of the current (working)
3298directory.
3299.IP quit
3300The
3301.I quit
3302signal,
3303generated by a control-\e
3304is used to terminate programs which are behaving unreasonably.
3305It normally produces a core image file (1.8).
3306.IP quotation
3307The process by which metacharacters are prevented their special
3308meaning, usually by using the character `\' in pairs, or by
3309using the character `\e' is referred to as
3310.I quotation
3311(1.4).
3312.IP redirection
3313The routing of input or output from or to a file is known
3314as
3315.I redirection
3316of input or output (1.3).
3317.IP repeat
3318The
3319.I repeat
3320command iterates another command a specified number of times (2.6).
3321.IP \s-2RUBOUT\s0
3322The \s-2RUBOUT\s0 or \s-2DELETE\s0
3323key generates an interrupt signal which is used to stop programs
3324or to cause them to return and prompt for more input (2.6).
3325.IP script
3326Sequences of shell commands placed in a file are called shell command
3327scripts.
3328It is often possible to perform simple tasks using these scripts without
3329writing a program in a language such as C, by
3330using the shell to selectively run other programs (3.2, 3.3, 3.10).
3331.IP set
3332The builtin
3333.I set
3334command is used to assign new values to shell variables
3335and to show the values of the current variables.
3336Many shell variables have special meaning to the shell itself.
3337Thus by using the set command the behavior of the shell can be affected (2.1).
3338.IP setenv
3339On version 7 systems variables in the environment `environ (5)'
3340can be changed by using the
3341.I setenv
3342builtin command (2.6).
3343The
3344.I printenv
3345command can be used to print the value of the variables in the environment.
3346Currently, only the \s-2VAX/UNIX\s0 system on the fifth floor of Evans Hall
3347is running version 7 \s-2UNIX\s0.
3348The other systems are running version 6, where
3349.I setenv
3350is not necessary and does not exist.
3351.IP shell
3352A shell is a command language interpreter.
3353It is possible to write and run your own shell,
3354as shells are no different than any other programs as far as the
3355system is concerned.
3356This manual deals with the details of one particular shell,
3357called
3358.I csh.
3359.IP "shell script"
3360See
3361.I script
3362(3.2, 3.3, 3.10).
3363.IP sort
3364The
3365.I sort
3366program sorts a sequence of lines in ways that can be controlled
3367by argument flags (1.5).
3368.IP source
3369The
3370.I source
3371command causes the shell to read commands from a specified file.
3372It is most useful for reading files such as
3373.I \&.cshrc
3374after changing them (2.6).
3375.IP "special character"
3376.br
3377See
3378.I metacharacters
3379and the
3380appendix to this manual.
3381.IP standard
3382We refer often to the
3383.I "standard input"
3384and
3385.I "standard output"
3386of commands.
3387See
3388.I input
3389and
3390.I output
3391(1.3, 3.8).
3392.IP status
3393A command normally returns a
3394.I status
3395when it finishes.
3396By convention a
3397.I status
3398of zero indicates that the command succeeded.
3399Commands may return non-zero status to indicate that some abnormal
3400event has occurred.
3401The shell variable
3402.I status
3403is set to the status returned by the last command.
3404It is most useful in shell commmand scripts (3.5, 3.6).
3405.IP substitution
3406The shell implements a number of
3407.I substitutions
3408where sequences indicated by metacharacters are replaced by other sequences.
3409Notable examples of this are history substitution keyed by the
3410metacharacter `!' and variable substitution indicated by `$'.
3411We also refer to substitutions as
3412.I expansions
3413(3.4).
3414.IP switch
3415The
3416.I switch
3417command of the shell allows the shell
3418to select one of a number of sequences of commands based on an
3419argument string.
3420It is similar to the
3421.I switch
3422statement in the language C (3.7).
3423.IP termination
3424When a command which is being executed finished we say it undergoes
3425.I termination
3426or
3427.I terminates.
3428Commands normally terminate when they read an end-of-file
3429from their standard input.
3430It is also possible to terminate commands by sending them
3431an
3432.I interrupt
3433or
3434.I quit
3435signal (1.8).
3436The
3437.I kill
3438program terminates specified command whose numbers are given (2.6).
3439.IP then
3440The
3441.I then
3442command is part of the shells
3443`if-then-else-endif' control construct used in command scripts (3.6).
3444.IP time
3445The
3446.I time
3447command can be used to measure the amount of \s-2CPU\s0
3448and real time consumed by a specified command (2.1, 2.6).
3449.IP troff
3450The
3451.I troff
3452program is used to typeset documents.
3453See also
3454.I nroff
3455(3.2).
3456.IP tset
3457The
3458.I tset
3459program is used to set standard erase and kill characters
3460and to tell the system what kind of terminal you are using.
3461It is often invoked in a
3462.I \&.login
3463file (2.1).
3464.IP unalias
3465The
3466.I unalias
3467command removes aliases (2.6).
3468.IP \s-2UNIX\s0
3469\s-2UNIX\s0 is an operating system on which
3470.I csh
3471runs.
3472\s-2UNIX\s0 provides facilities which allow
3473.I csh
3474to invoke other programs such as editors and text formatters which
3475you may wish to use.
3476.IP unset
3477The
3478.I unset
3479command removes the definitions of shell variables (2.2, 2.6).
3480.IP "variable expansion"
3481.br
3482See
3483.I variables
3484and
3485.I expansion
3486(2.2, 3.4).
3487.IP variables
3488Variables in
3489.I csh
3490hold one or more strings as value.
3491The most common use of variables is in controlling the behavior
3492of the shell.
3493See
3494.I path,
3495.I noclobber,
3496and
3497.I ignoreeof
3498for examples.
3499Variables such as
3500.I argv
3501are also used in writing shell programs (shell command scripts)
3502(2.2).
3503.IP verbose
3504The
3505.I verbose
3506shell variable can be set to cause commands to be echoed
3507after they are history expanded.
3508This is often useful in debugging shell scripts.
3509The
3510.I verbose
3511variable is set by the shells
3512.I \-v
3513command line option (3.10).
3514.IP wait
3515The builtin command
3516.I wait
3517causes the shell to pause, and not prompt,
3518until all commands run in the background have terminated (2.6).
3519.IP where
3520The
3521.I where
3522command shows where the users named as arguments are logged into the
3523system (2.3).
3524.IP while
3525The
3526.I while
3527builtin control construct is used in shell command scripts (3.7).
3528.IP word
3529A sequence of characters which forms an argument to a command is called
3530a
3531.I word.
3532Many characters which are neither letters, digits, `\-', `.' or `/'
3533form words all by themselves even if they are not surrounded
3534by blanks.
3535Any sequence of character may be made into a word by surrounding it
3536with `\'' characters
3537except for the characters `\'' and `!' which require special treatment
3538(1.1, 1.6).
3539This process of placing special characters
3540in words without their special meaning is called
3541.I quoting.
3542.IP "working directory"
3543.br
3544At an given time you are in one particular directory, called
3545your working directory.
3546This directories name is printed by the
3547.I pwd
3548command and the files listed by
3549.I ls
3550are the ones in this directory.
3551You can change working directories using
3552.I chdir.
3553.IP write
3554The
3555.I write
3556command is used to communicate with other users who are logged in to
3557\s-2UNIX\s0 (2.3).