2 .\" Copyright (c) 1980, 1993
3 .\" The Regents of the University of California. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 4. Neither the name of the University nor the names of its contributors
14 .\" may be used to endorse or promote products derived from this software
15 .\" without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 .\" @(#)csh.2 8.1 (Berkeley) 6/8/93
34 Details on the shell for terminal users
36 Shell startup and termination
38 When you login, the shell is started by the system in your
40 directory and begins by reading commands from a file
43 All shells which you may start during your terminal session will
45 We will later see what kinds of commands are usefully placed there.
46 For now we need not have this file and the shell does not complain about
51 executed after you login to the system,
52 will, after it reads commands from
54 read commands from a file
56 also in your home directory.
57 This file contains commands which you wish to do each time you login
58 to the \s-2UNIX\s0 system.
61 file looks something like:
64 set mail=(/usr/spool/mail/bill)
65 echo "${prompt}users" ; users
67 \'set noglob ; eval \`tset \-s \-m dialup:c100rv4pna \-m plugboard:?hp2621nl \!*\`\';
68 ts; stty intr ^C kill ^U crt
69 set time=15 history=10
77 This file contains several commands to be executed by \s-2UNIX\s0
81 command which is interpreted directly by the shell. It sets the shell
84 which causes the shell to not log me off if I hit ^D. Rather,
87 command to log off of the system.
90 variable, I ask the shell to watch for incoming mail to me. Every 5 minutes
91 the shell looks for this file and tells me if more mail has arrived there.
92 An alternative to this is to put the command
98 this will cause me to be notified immediately when mail arrives, and to
99 be shown the first few lines of the new message.
101 Next I set the shell variable `time' to `15' causing the shell to automatically
102 print out statistics lines for commands which execute for at least 15 seconds
103 of \s-2CPU\s+2 time. The variable `history' is set to 10 indicating that
104 I want the shell to remember the last 10 commands I type in its
110 ``ts'' which executes a
111 \fItset\fR\|(1) command setting up the modes of the terminal.
114 indicate the kinds of terminal which I usually use when not on a hardwired
115 port. I then execute ``ts'' and also use the
117 command to change the interrupt character to ^C and the line kill
120 I then run the `msgs' program, which provides me with any
121 system messages which I have not seen before; the `\-f' option here prevents
122 it from telling me anything if there are no new messages.
123 Finally, if my mailbox file exists, then I run the `mail' program to
126 When the `mail' and `msgs' programs finish, the shell will finish
129 file and begin reading commands from the terminal, prompting for each with
131 When I log off (by giving the
134 will print `logout' and execute commands from the file `.logout'
135 if it exists in my home directory.
136 After that the shell will terminate and \s-2UNIX\s0 will log
138 If the system is not going down, I will receive a new login message.
139 In any case, after the `logout' message the shell is committed to terminating
140 and will take no further input from my terminal.
144 The shell maintains a set of
146 We saw above the variables
150 which had values `10' and `15'.
151 In fact, each shell variable has as value an array of
154 Shell variables may be assigned values by the set command. It has
155 several forms, the most useful of which was given above and is
160 Shell variables may be used to store values which are to
161 be used in commands later through a substitution mechanism.
162 The shell variables most commonly referenced are, however, those which the
163 shell itself refers to.
164 By changing the values of these variables one can directly affect the
165 behavior of the shell.
167 One of the most important variables is the variable
169 This variable contains a sequence of directory names where the shell
170 searches for commands.
173 command with no arguments
174 shows the value of all variables currently defined (we usually say
177 The default value for path will be shown by
186 path (. /usr/ucb /bin /usr/bin)
195 This output indicates that the variable path points to the current
196 directory `.' and then `/usr/ucb', `/bin' and `/usr/bin'.
197 Commands which you may write might be in `.' (usually one of
199 Commands developed at Berkeley, live in `/usr/ucb'
200 while commands developed at Bell Laboratories live in `/bin' and `/usr/bin'.
202 A number of locally developed programs on the system live in the directory
204 If we wish that all shells which we invoke to have
205 access to these new programs we can place the command
207 set path=(. /usr/ucb /bin /usr/bin /usr/local)
211 in our home directory.
212 Try doing this and then logging out and back in and do
216 again to see that the value assigned to
220 Another directory that might interest you is /usr/new, which contains
221 many useful user-contributed programs provided with Berkeley Unix.
224 One thing you should be aware of is that the shell examines each directory
225 which you insert into your path and determines which commands are contained
226 there. Except for the current directory `.', which the shell treats specially,
227 this means that if commands are added to a directory in your search path after
228 you have started the shell, they will not necessarily be found by the shell.
229 If you wish to use a command which has been added in this way, you should
234 to the shell, which will cause it to recompute its internal table of command
235 locations, so that it will find the newly added command.
236 Since the shell has to look in the current directory `.' on each command,
237 placing it at the end of the path specification usually works equivalently
238 and reduces overhead.
240 Other useful built in variables are the variable
242 which shows your home directory,
244 which contains your current working directory,
247 which can be set in your
249 file to tell the shell not to exit when it receives an end-of-file from
250 a terminal (as described above).
251 The variable `ignoreeof'
252 is one of several variables which the shell does not care about the
253 value of, only whether they are
257 Thus to set this variable you simply do
265 These give the variable `ignoreeof' no value, but none is desired or required.
267 Finally, some other built-in shell variables of use are the
276 which redirects the standard output of a command
277 will overwrite and destroy the previous contents of the named file.
278 In this way you may accidentally overwrite a file which is valuable.
279 If you would prefer that the shell not overwrite files in this
291 would cause a diagnostic if `now' existed already.
296 if you really wanted to overwrite the contents of `now'.
297 The `>!' is a special metasyntax indicating that clobbering the
300 \(dgThe space between the `!' and the word `now' is critical here, as `!now'
301 would be an invocation of the
303 mechanism, and have a totally different effect.
306 The shell's history list
308 The shell can maintain a
310 into which it places the words
311 of previous commands.
312 It is possible to use a notation to reuse commands or words
313 from commands in forming new commands.
314 This mechanism can be used to repeat previous commands or to
315 correct minor typing mistakes in commands.
317 The following figure gives a sample session involving typical usage of the
318 history mechanism of the shell.
329 "bug.c", line 4: newline in string or char constant
330 "bug.c", line 5: syntax error
353 a.out: 2784+364+1028 = 4176b = 0x1050b
354 bug: 2784+364+1028 = 4176b = 0x1050b
357 \(mirwxr\(mixr\(mix 1 bill 3932 Dec 19 09:41 a.out
358 \(mirwxr\(mixr\(mix 1 bill 3932 Dec 19 09:42 bug
362 spp: Command not found.
367 4 printf("hello\en");
370 num bug.c | ssp | lpr
374 In this example we have a very simple C program which has a bug (or two)
375 in it in the file `bug.c', which we `cat' out on our terminal. We then
376 try to run the C compiler on it, referring to the file again as `!$',
377 meaning the last argument to the previous command. Here the `!' is the
378 history mechanism invocation metacharacter, and the `$' stands for the last
379 argument, by analogy to `$' in the editor which stands for the end of the line.
380 The shell echoed the command, as it would have been typed without use of
381 the history mechanism, and then executed it.
382 The compilation yielded error diagnostics so we now run the editor on the
383 file we were trying to compile, fix the bug, and run the C compiler again,
384 this time referring to this command simply as `!c', which repeats the last
385 command which started with the letter `c'. If there were other
386 commands starting with `c' done recently we could have said `!cc' or even
387 `!cc:p' which would have printed the last command starting with `cc'
388 without executing it.
390 After this recompilation, we ran the resulting `a.out' file, and then
391 noting that there still was a bug, ran the editor again. After fixing
392 the program we ran the C compiler again, but tacked onto the command
393 an extra `\-o bug' telling the compiler to place the resultant binary in
394 the file `bug' rather than `a.out'. In general, the history mechanisms
395 may be used anywhere in the formation of new commands and other characters
396 may be placed before and after the substituted commands.
398 We then ran the `size' command to see how large the binary program images
399 we have created were, and then an `ls \-l' command with the same argument
400 list, denoting the argument list `\!*'.
401 Finally we ran the program `bug' to see that its output is indeed correct.
403 To make a numbered listing of the program we ran the `num' command on the file `bug.c'.
404 In order to compress out blank lines in the output of `num' we ran the
405 output through the filter `ssp', but misspelled it as spp. To correct this
406 we used a shell substitute, placing the old text and new text between `^'
407 characters. This is similar to the substitute command in the editor.
408 Finally, we repeated the same command with `!!', but sent its output to the
411 There are other mechanisms available for repeating commands. The
413 command prints out a number of previous commands with numbers by which
414 they can be referenced. There is a way to refer to a previous command
415 by searching for a string which appeared in it, and there are other,
416 less useful, ways to select arguments to include in a new command.
417 A complete description of all these mechanisms
418 is given in the C shell manual pages in the \s-2UNIX\s0 Programmer's Manual.
424 mechanism which can be used to make transformations on input commands.
425 This mechanism can be used to simplify the commands you type,
426 to supply default arguments to commands,
427 or to perform transformations on commands and their arguments.
428 The alias facility is similar to a macro facility.
429 Some of the features obtained by aliasing can be obtained also
430 using shell command files, but these take place in another instance
431 of the shell and cannot directly affect the current shells environment
432 or involve commands such as
434 which must be done in the current shell.
436 As an example, suppose that there is a new version of the mail program
437 on the system called `newmail'
438 you wish to use, rather than the standard mail program which is called
440 If you place the shell command
446 file, the shell will transform an input line of the form
450 into a call on `newmail'.
451 More generally, suppose we wish the command `ls' to always show
452 sizes of files, that is to always do `\-s'.
461 creating a new command syntax `dir'
462 which does an `ls \-s'.
467 then the shell will translate this to
474 mechanism can be used to provide short names for commands,
475 to provide default arguments,
476 and to define new short commands in terms of other commands.
477 It is also possible to define aliases which contain multiple
478 commands or pipelines, showing where the arguments to the original
479 command are to be substituted using the facilities of the
483 alias cd \'cd \e!* ; ls \'
487 command after each change directory
490 We enclosed the entire alias definition in `\'' characters to prevent
491 most substitutions from occurring and the character `;' from being
492 recognized as a metacharacter.
493 The `!' here is escaped with a `\e' to prevent it from being interpreted
494 when the alias command is typed in.
495 The `\e!*' here substitutes the entire argument list to the pre-aliasing
497 command, without giving an error if there were no arguments.
498 The `;' separating commands is used here
499 to indicate that one command is to be done and then the next.
500 Similarly the definition
502 alias whois \'grep \e!^ /etc/passwd\'
504 defines a command which looks up its first argument in the password file.
507 The shell currently reads the
509 file each time it starts up. If you place a large number of commands
510 there, shells will tend to start slowly. A mechanism for saving the shell
511 environment after reading the \fI\&.cshrc\fR file and quickly restoring it is
512 under development, but for now you should try to limit the number of
513 aliases you have to a reasonable number... 10 or 15 is reasonable,
514 50 or 60 will cause a noticeable delay in starting up shells, and make
515 the system seem sluggish when you execute commands from within the editor
518 More redirection; >> and >&
520 There are a few more notations useful to the terminal user
521 which have not been introduced yet.
523 In addition to the standard output, commands also have a
524 .I "diagnostic output"
525 which is normally directed to the terminal even when the standard output
526 is redirected to a file or a pipe.
527 It is occasionally desirable to direct the diagnostic output along with
529 For instance if you want to redirect the output of a long running command
530 into a file and wish to have a record of any error diagnostic it produces
535 The `>&' here tells the shell to route both the diagnostic output and the
536 standard output into `file'.
537 Similarly you can give the command
541 to route both standard and diagnostic output through the pipe
542 to the line printer daemon
545 \(dd A command of the form
550 exists, and is used when
557 Finally, it is possible to use the form
561 to place output at the end of an existing file.\(dg
565 is set, then an error will result if
567 does not exist, otherwise the shell will create
575 makes it not be an error for file to not exist when
580 Jobs; Background, Foreground, or Suspended
582 When one or more commands
583 are typed together as a pipeline or as a sequence of commands separated by
586 is created by the shell consisting of these commands together as a unit.
587 Single commands without pipes or semicolons create the simplest jobs.
588 Usually, every line typed to the shell creates a job.
589 Some lines that create jobs (one per line) are
592 ls \-s | sort \-n | head \-5
596 If the metacharacter `&' is typed
597 at the end of the commands, then the job is started as a
599 job. This means that the shell does not wait for it to complete but
600 immediately prompts and is ready for another command. The job runs
601 .I "in the background"
602 at the same time that normal jobs, called
604 jobs, continue to be read and executed by the shell one at a time.
611 program, which reports on the disk usage of your working directory (as well as
612 any directories below it), put the output into the file `usage' and return
613 immediately with a prompt for the next command without out waiting for
617 program would continue executing in the background
618 until it finished, even though you can type and execute more commands in the
621 job terminates, a message is typed by the shell just before the next prompt
622 telling you that the job has completed.
623 In the following example the
625 job finishes sometime during the
628 command and its completion is reported just before
636 How do you know when a background job is finished?
639 [1] \- Done du > usage
643 If the job did not terminate normally the `Done' message might say
644 something else like `Killed'.
646 terminations of background jobs to be reported at the time they occur
647 (possibly interrupting the output of other foreground jobs), you can set
650 variable. In the previous example this would mean that the
651 `Done' message might have come right in the middle of the message to
653 Background jobs are unaffected by any signals from the keyboard like
654 the \s-2STOP\s0, \s-2INTERRUPT\s0, or \s-2QUIT\s0 signals mentioned earlier.
656 Jobs are recorded in a table inside the shell until they terminate.
657 In this table, the shell remembers the command names, arguments and the
659 of all commands in the job as well as the working directory where the job was
661 Each job in the table is either running
662 .I "in the foreground"
663 with the shell waiting for it to terminate, running
664 .I "in the background,"
667 Only one job can be running in the foreground at one time, but several
668 jobs can be suspended or running in the background at once. As each job
669 is started, it is assigned a small identifying
672 which can be used later to refer to the job in the commands described below.
674 the same until the job terminates and then are re-used.
676 When a job is started in the background using `&', its number, as well
677 as the process numbers of all its (top level) commands, is typed by the shell
678 before prompting you for another command.
681 % ls \-s | sort \-n > usage &
685 runs the `ls' program with the `\-s' options, pipes this output into
686 the `sort' program with the `\-n' option which puts its output into the
688 Since the `&' was at the end of the line, these two programs were started
689 together as a background job. After starting the job, the shell prints
690 the job number in brackets (2 in this case) followed by the process number
691 of each program started in the job. Then the shell immediates prompts for
692 a new command, leaving the job running simultaneously.
694 As mentioned in section 1.8, foreground jobs become
697 which sends a \s-2STOP\s0 signal to the currently running
698 foreground job. A background job can become suspended by using the
700 command described below. When jobs are suspended they merely stop
701 any further progress until started again, either in the foreground
702 or the background. The shell notices when a job becomes stopped and
703 reports this fact, much like it reports the termination of background jobs.
704 For foreground jobs this looks like
711 `Stopped' message is typed by the shell when it notices that the
714 For background jobs, using the
722 [1] + Stopped (signal) sort usage
726 Suspending foreground jobs can be very useful when you need to temporarily
727 change what you are doing (execute other commands) and then return to
728 the suspended job. Also, foreground jobs can be suspended and then
729 continued as background jobs using the
731 command, allowing you to continue other work and
732 stop waiting for the foreground job to finish. Thus
741 starts `du' in the foreground, stops it before it finishes, then continues
742 it in the background allowing more foreground commands to be executed.
743 This is especially helpful
744 when a foreground job ends up taking longer than you expected and you
745 wish you had started it in the background in the beginning.
749 commands can take an argument that identifies a particular
751 All job name arguments begin with the character `%', since some of the
752 job control commands also accept process numbers (printed by the
755 The default job (when no argument is given) is called the
757 job and is identified by a `+' in the output of the
759 command, which shows you which jobs you have.
760 When only one job is stopped or running in the background (the usual case)
761 it is always the current job thus no argument is needed.
762 If a job is stopped while running in the foreground it becomes the
764 job and the existing current job becomes the
766 job \- identified by a `\-' in the output of
768 When the current job terminates, the previous job becomes the current job.
769 When given, the argument is either `%\-' (indicating
770 the previous job); `%#', where # is the job number;
771 `%pref' where pref is some unique prefix of the command name
772 and arguments of one of the jobs; or `%?' followed by some string found
773 in only one of the jobs.
777 command types the table of jobs, giving the job number,
778 commands and status (`Stopped' or `Running') of each background or
779 suspended job. With the `\-l' option the process numbers are also
784 % ls \-s | sort \-n > myfile &
791 [1] \(mi Running du > usage
792 [2] Running ls \-s | sort \-n > myfile
793 [3] \(pl Stopped mail bill
795 ls \-s | sort \-n > myfile
802 command runs a suspended or background job in the foreground. It is
803 used to restart a previously suspended job or change a background job
804 to run in the foreground (allowing signals or input from the terminal).
805 In the above example we used
807 to change the `ls' job from the
808 background to the foreground since we wanted to wait for it to
809 finish before looking at its output file.
812 command runs a suspended job in the background. It is usually used
813 after stopping the currently running foreground job with the
814 \s-2STOP\s0 signal. The combination of the \s-2STOP\s0 signal and the
816 command changes a foreground job into a background job.
819 command suspends a background job.
823 command terminates a background or suspended job immediately.
824 In addition to jobs, it may be given process numbers as arguments,
827 Thus, in the example above, the running
829 command could have been terminated by the command
833 [1] Terminated du > usage
840 command (not the variable mentioned earlier) indicates that the termination
841 of a specific job should be
842 reported at the time it finishes instead of waiting for the next prompt.
844 If a job running in the background tries to read input from the terminal
845 it is automatically stopped. When such a job is then run in the
846 foreground, input can be given to the job. If desired, the job can
847 be run in the background again until it requests input again.
848 This is illustrated in the following sequence where the `s' command in the
849 text editor might take a long time.
854 1,$s/thisword/thatword/
860 . . . some foreground commands
862 [1] Stopped (tty input) ed bigfile
871 So after the `s' command was issued, the `ed' job was stopped with ^Z
872 and then put in the background using
874 Some time later when the `s' command was finished,
876 tried to read another command and was stopped because jobs
877 in the background cannot read from the terminal. The
879 command returned the `ed' job to the foreground where it could once again
880 accept commands from the terminal.
886 causes all background jobs run on your terminal to stop
887 when they are about to
888 write output to the terminal. This prevents messages from background
889 jobs from interrupting foreground job output and allows you to run
890 a job in the background without losing terminal output. It also
891 can be used for interactive programs that sometimes have long
892 periods without interaction. Thus each time it outputs a prompt for more
893 input it will stop before the prompt. It can then be run in the
896 more input can be given and, if necessary stopped and returned to
899 command might be a good thing to put in your
901 file if you do not like output from background jobs interrupting
902 your work. It also can reduce the need for redirecting the output
903 of background jobs if the output is not very big:
909 \&. . . some time later
912 [1] Stopped (tty output) wc hugefile
919 Thus after some time the `wc' command, which counts the lines, words
920 and characters in a file, had one line of output. When it tried to
921 write this to the terminal it stopped. By restarting it in the
922 foreground we allowed it to write on the terminal exactly when we were
923 ready to look at its output.
924 Programs which attempt to change the mode of the terminal will also
925 block, whether or not
927 is set, when they are not in the foreground, as
928 it would be very unpleasant to have a background job change the state
933 command only prints jobs started in the currently executing shell,
934 it knows nothing about background jobs started in other login sessions
935 or within shell files. The
937 can be used in this case to find out about background jobs not started
938 in the current shell.
942 As mentioned in section 1.6, the shell is always in a particular
943 .I "working directory."
944 The `change directory' command
950 changes the working directory of the shell,
951 that is, changes the directory you
954 It is useful to make a directory for each project you wish to work on
955 and to place all files related to that project in that directory.
956 The `make directory' command,
958 creates a new directory.
961 (`print working directory') command
962 reports the absolute pathname of the working directory of the shell,
963 that is, the directory you are
965 Thus in the example below:
975 the user has created and moved to the
978 where, for example, he might
979 place a group of related files.
981 No matter where you have moved to in a directory hierarchy,
982 you can return to your `home' login directory by doing just
987 The name `..' always means the directory above the current one in
992 changes the shell's working directory to the one directly above the
994 The name `..' can be used in any
1000 change to the directory `programs' contained in the directory
1001 above the current one.
1002 If you have several directories for different
1003 projects under, say, your home directory,
1004 this shorthand notation
1005 permits you to switch easily between them.
1007 The shell always remembers the pathname of its current working directory in
1010 The shell can also be requested to remember the previous directory when
1011 you change to a new working directory. If the `push directory' command
1013 is used in place of the
1015 command, the shell saves the name of the current working directory
1017 .I "directory stack"
1018 before changing to the new one.
1019 You can see this list at any time by typing the `directories'
1024 % pushd newpaper/references
1025 ~/newpaper/references ~
1026 % pushd /usr/lib/tmac
1027 /usr/lib/tmac ~/newpaper/references ~
1029 /usr/lib/tmac ~/newpaper/references ~
1031 ~/newpaper/references ~
1036 The list is printed in a horizontal line, reading left to right,
1038 shorthand for your home directory\(emin this case `/usr/bill'.
1039 The directory stack is printed whenever there is more than one
1040 entry on it and it changes.
1041 It is also printed by a
1045 is usually faster and more informative than
1047 since it shows the current working directory as well as any
1048 other directories remembered in the stack.
1052 command with no argument
1053 alternates the current directory with the first directory in the
1057 command without an argument returns you to the directory you were in prior to
1058 the current one, discarding the previous current directory from the
1059 stack (forgetting it).
1062 several times in a series takes you backward through the directories
1063 you had been in (changed to) by
1066 There are other options to
1070 to manipulate the contents of the directory stack and to change
1071 to directories not at the top of the stack; see the
1073 manual page for details.
1075 Since the shell remembers the working directory in which each job
1076 was started, it warns you when you might be confused by restarting
1077 a job in the foreground which has a different working directory than the
1078 current working directory of the shell. Thus if you start a background
1079 job, then change the shell's working directory and then cause the
1080 background job to run in the foreground, the shell warns you that the
1081 working directory of the currently running foreground job is different
1082 from that of the shell.
1098 ed prog.c (wd: ~/myproject)
1100 This way the shell warns you when there
1101 is an implied change of working directory, even though no cd command was
1102 issued. In the above example the `ed' job was still in `/mnt/bill/project'
1103 even though the shell had changed to `/mnt/bill'.
1104 A similar warning is given when such a foreground job
1105 terminates or is suspended (using the \s-2STOP\s0 signal) since
1106 the return to the shell again implies a change of working directory.
1109 ed prog.c (wd: ~/myproject)
1110 . . . after some editing
1115 These messages are sometimes confusing if you use programs that change
1116 their own working directories, since the shell only remembers which
1117 directory a job is started in, and assumes it stays there.
1120 will type the working directory
1121 of suspended or background jobs when it is different
1122 from the current working directory of the shell.
1124 Useful built-in commands
1126 We now give a few of the useful built-in commands of the shell describing
1131 command described above is used to assign new aliases and to show the
1133 With no arguments it prints the current aliases.
1134 It may also be given only one argument such as
1138 to show the current alias for, e.g., `ls'.
1142 command prints its arguments.
1145 or as an interactive command
1146 to see what filename expansions will produce.
1150 command will show the contents of the history list.
1151 The numbers given with the history events can be used to reference
1152 previous events which are difficult to reference using the
1153 contextual mechanisms introduced above.
1154 There is also a shell variable called
1156 By placing a `!' character in its value the shell will there substitute
1157 the number of the current command in the history list.
1158 You can use this number to refer to this command in a history substitution.
1161 set prompt=\'\e! % \'
1163 Note that the `!' character had to be
1165 here even within `\'' characters.
1169 command is used to restrict use of resources.
1170 With no arguments it prints the current limitations:
1175 datasize 5616 kbytes
1176 stacksize 512 kbytes
1177 coredumpsize unlimited
1180 Limits can be set, e.g.:
1182 limit coredumpsize 128k
1184 Most reasonable units abbreviations will work; see the
1186 manual page for more details.
1190 command can be used to terminate a login shell which has
1196 command causes the shell to recompute a table of where commands are
1197 located. This is necessary if you add a command to a directory
1198 in the current shell's search path and wish the shell to find it,
1199 since otherwise the hashing algorithm may tell the shell that the
1200 command wasn't in that directory when the hash table was computed.
1204 command can be used to repeat a command several times.
1205 Thus to make 5 copies of the file
1211 repeat 5 cat one >> five
1217 to set variables in the environment.
1222 will set the value of the environment variable \s-2TERM\s0
1227 exists which will print out the environment.
1233 PATH=:/usr/ucb:/bin:/usr/bin:/usr/local
1241 command can be used to force the current shell to read commands from
1247 can be used after editing in a change to the
1249 file which you wish to take effect right away.
1253 command can be used to cause a command to be timed no matter how much
1254 \s-2CPU\s0 time it takes.
1257 % time cp /etc/rc /usr/bill/rc
1258 0.0u 0.1s 0:01 8% 2+1k 3+2io 1pf+0w
1259 % time wc /etc/rc /usr/bill/rc
1261 52 178 1347 /usr/bill/rc
1263 0.1u 0.1s 0:00 13% 3+3k 5+3io 7pf+0w
1268 command used a negligible amount of user time (u)
1269 and about 1/10th of a system time (s); the elapsed time was 1 second (0:01),
1270 there was an average memory usage of 2k bytes of program space and 1k
1271 bytes of data space over the cpu time involved (2+1k); the program
1272 did three disk reads and two disk writes (3+2io), and took one page fault
1273 and was not swapped (1pf+0w).
1274 The word count command
1276 on the other hand used 0.1 seconds of user time and 0.1 seconds of system
1277 time in less than a second of elapsed time.
1278 The percentage `13%' indicates that over the period when it was active
1279 the command `wc' used an average of 13 percent of the available \s-2CPU\s0
1280 cycles of the machine.
1286 commands can be used
1287 to remove aliases and variable definitions from the shell, and
1289 removes variables from the environment.
1293 This concludes the basic discussion of the shell for terminal users.
1294 There are more features of the shell to be discussed here, and all
1295 features of the shell are discussed in its manual pages.
1296 One useful feature which is discussed later is the
1298 built-in command which can be used to run the same command
1299 sequence with a number of different arguments.
1301 If you intend to use \s-2UNIX\s0 a lot you should look through
1302 the rest of this document and the csh manual pages (section1) to become familiar
1303 with the other facilities which are available to you.