4. Other, less commonly used, shell features
4.1. Loops at the terminal; variables as vectors
It is occasionally useful to use the
foreach
control structure at the terminal to aid in performing a number
of similar commands.
For instance, there were at one point three shells in use on the Cory UNIX
system at Cory Hall,
`/bin/sh',
`/bin/nsh',
and
`/bin/csh'.
To count the number of persons using each shell one could have issued
the commands
-
% grep -c csh$ /etc/passwd
27
% grep -c nsh$ /etc/passwd
128
% grep -c -v sh$ /etc/passwd
430
%
Since these commands are very similar we can use
foreach
to do this more easily.
-
% foreach i ('sh$' 'csh$' '-v sh$')
? grep -c $i /etc/passwd
? end
27
128
430
%
Note here that the shell prompts for
input with `? ' when reading the body of the loop.
Very useful with loops are variables which contain lists of filenames
or other words.
You can, for example, do
-
% set a=(`ls`)
% echo $a
csh.n csh.rm
% ls
csh.n
csh.rm
% echo $#a
2
%
The
set
command here gave the variable
a
a list of all the filenames in the current directory as value.
We can then iterate over these names to perform any chosen function.
The output of a command within ``' characters is converted by
the shell to a list of words.
You can also place the ``' quoted string within `"' characters
to take each (non-empty) line as a component of the variable;
preventing the lines from being split into words at blanks and tabs.
A modifier `:x' exists which can be used later to expand each component
of the variable into another variable splitting it into separate words
at embedded blanks and tabs.
4.2. Braces { ... } in argument expansion
Another form of filename expansion, alluded
to before involves the characters `{' and `}'.
These characters specify that the contained strings, separated by `,'
are to be consecutively substituted into the containing characters
and the results expanded left to right.
Thus
-
A{str1,str2,...strn}B
expands to
-
Astr1B Astr2B ... AstrnB
This expansion occurs before the other filename expansions, and may
be applied recursively (i.e. nested).
The results of each expanded string are sorted separately, left
to right order being preserved.
The resulting filenames are not required to exist if no other expansion
mechanisms are used.
This means that this mechanism can be used to generate arguments which are
not filenames, but which have common parts.
A typical use of this would be
-
mkdir ~/{hdrs,retrofit,csh}
to make subdirectories `hdrs', `retrofit' and `csh'
in your home directory.
This mechanism is most useful when the common prefix is longer
than in this example, i.e.
-
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
4.3. Command substitution
A command enclosed in ``' characters is replaced, just before
filenames are expanded, by the output from that command.
Thus it is possible to do
-
set pwd=`pwd`
to save the current directory in the variable
pwd
or to do
-
ex `grep -l TRACE *.c`
to run the editor
ex
supplying as arguments those files whose names end in `.c'
which have the string `TRACE' in them.*
4.4. Other details not covered here
In particular circumstances it may be necessary to know the exact
nature and order of different substitutions performed by the shell.
The exact meaning of certain combinations of quotations is also
occasionally important.
These are detailed fully in its manual section.
The shell has a number of command line option flags mostly of use
in writing UNIX programs,
and debugging shell scripts.
See the csh(1) manual section for a list of these options.
Appendix - Special characters
The following table lists the special characters of
csh
and the UNIX system, giving for each the section(s) in which it
is discussed.
A number of these characters also have special meaning in expressions.
See the
csh
manual section
for a complete list.
Syntactic metacharacters
-
; 2.4 separates commands to be executed sequentially
| 1.5 separates commands in a pipeline
( ) 2.2,3.6 brackets expressions and variable values
& 2.5 follows commands to be executed without waiting for completion
Filename metacharacters
-
/ 1.6 separates components of a file's pathname
. 1.6 separates root parts of a file name from extensions
? 1.6 expansion character matching any single character
* 1.6 expansion character matching any sequence of characters
[ ] 1.6 expansion sequence matching any single character from a set
~ 1.6 used at the beginning of a filename to indicate home directories
{ } 4.2 used to specify groups of arguments with common parts
Quotation metacharacters
-
\ 1.7 prevents meta-meaning of following single character
' 1.7 prevents meta-meaning of a group of characters
" 4.3 like ', but allows variable and command expansion
Input/output metacharacters
-
< 1.5 indicates redirected input
> 1.3 indicates redirected output
Expansion/substitution metacharacters
-
$ 3.4 indicates variable substitution
! 2.3 indicates history substitution
: 3.6 precedes substitution modifiers
^ 2.3 used in special forms of history substitution
` 4.3 indicates command substitution
Other metacharacters
-
# 1.3,3.6 begins scratch file names; indicates shell comments
- 1.2 prefixes option (flag) arguments to commands
% 2.6 prefixes job name specifications
Glossary
This glossary lists the most important terms introduced in the
introduction to the
shell and gives references to sections of the shell
document for further information about them.
References of the form
`pr (1)'
indicate that the command
pr
is in the UNIX User Reference manual in section 1.
You can look at an online copy of its manual page by doing
-
man 1 pr
References of the form (2.5)
indicate that more information can be found in section 2.5 of this
manual.
- .
-
Your current directory has the name `.' as well as the name printed
by the command
pwd;
see also
dirs.
The current directory `.' is usually the first
component
of the search path contained in the variable
path,
thus commands which are in `.' are found first (2.2).
The character `.' is also used in separating
components
of filenames
(1.6).
The character `.' at the beginning of a
component
of a
pathname
is treated specially and not matched by the
filename expansion
metacharacters `?', `*', and `[' `]' pairs (1.6).
- ..
-
Each directory has a file `..' in it which is a reference to its
parent directory.
After changing into the directory with
chdir,
i.e.
-
chdir paper
you can return to the parent directory by doing
-
chdir ..
The current directory is printed by
pwd
(2.7).
- a.out
-
Compilers which create executable images create them, by default, in the
file
a.out.
for historical reasons (2.3).
- absolute pathname
-
A
pathname
which begins with a `/' is
absolute
since it specifies the
path
of directories from the beginning
of the entire directory system - called the
root
directory.
Pathnames
which are not
absolute
are called
relative
(see definition of
relative pathname)
(1.6).
- alias
-
An
alias
specifies a shorter or different name for a UNIX
command, or a transformation on a command to be performed in
the shell.
The shell has a command
alias
which establishes
aliases
and can print their current values.
The command
unalias
is used to remove
aliases
(2.4).
- argument
-
Commands in UNIX receive a list of
argument
words.
Thus the command
-
echo a b c
consists of the
command name
`echo' and three
argument
words `a', `b' and `c'.
The set of
arguments
after the
command name
is said to be the
argument list
of the command (1.1).
- argv
-
The list of arguments to a command written in the shell language
(a shell script or shell procedure) is stored in a variable called
argv
within the shell.
This name is taken from the conventional name in the
C programming language (3.4).
- background
-
Commands started without waiting for them to complete are called
background
commands (2.6).
- base
-
A filename is sometimes thought of as consisting of a
base
part, before any `.' character, and an
extension
- the part after
the `.'. See
filename
and
extension
(1.6) and basename (1).
- bg
-
The
bg
command causes a
suspended
job to continue execution in the
background
(2.6).
- bin
-
A directory containing binaries of programs and shell scripts to be
executed is typically called a
bin
directory.
The standard system
bin
directories are `/bin' containing the most
heavily used commands and `/usr/bin' which contains most other user
programs.
Programs developed at UC Berkeley live in `/usr/ucb', while locally
written programs live in `/usr/local'. Games are kept in the directory
`/usr/games'.
You can place binaries in any directory.
If you wish to execute them often, the name of the directories
should be a
component
of the variable
path.
- break
-
Break
is a builtin command used to exit from loops within the control
structure of the shell (3.7).
- breaksw
-
The
breaksw
builtin command is used to exit from a
switch
control structure, like a
break
exits from loops (3.7).
- builtin
-
A command executed directly by the shell is called a
builtin
command.
Most commands in UNIX are not built into the shell,
but rather exist as files in
bin
directories.
These commands are accessible because the directories in which
they reside are named in the
path
variable.
- case
-
A
case
command is used as a label in a
switch
statement in the shell's control structure, similar to that of the
language C.
Details are given in the shell documentation `csh (1)' (3.7).
- cat
-
The
cat
program catenates a list of specified files on the
standard output.
It is usually used to look at the contents of a single file on the terminal,
to `cat a file' (1.8, 2.3).
- cd
-
The
cd
command is used to change the
working directory.
With no arguments,
cd
changes your
working directory
to be your
home
directory (2.4, 2.7).
- chdir
-
The
chdir
command is a synonym for
cd.
Cd
is usually used because it is easier to type.
- chsh
-
The
chsh
command is used to change the shell which you use on UNIX.
By default, you use an different version of the shell
which resides in `/bin/sh'.
You can change your shell to `/bin/csh' by doing
-
chsh your-login-name /bin/csh
Thus I would do
-
chsh bill /bin/csh
It is only necessary to do this once.
The next time you log in to UNIX after doing this command,
you will be using
csh
rather than the shell in `/bin/sh' (1.9).
- cmp
-
Cmp
is a program which compares files.
It is usually used on binary files, or to see if two files are identical (3.6).
For comparing text files the program
diff,
described in `diff (1)' is used.
- command
-
A function performed by the system, either by the shell
(a builtin
command)
or by a program residing in a file in
a directory within the UNIX system, is called a
command
(1.1).
- command name
-
When a command is issued, it consists of a
command name,
which is the first word of the command,
followed by arguments.
The convention on UNIX is that the first word of a
command names the function to be performed (1.1).
- command substitution
-
The replacement of a command enclosed in ``' characters
by the text output by that command
is called
command substitution
(4.3).
- component
-
A part of a
pathname
between `/' characters is called a
component
of that
pathname.
A variable
which has multiple strings as value is said to have
several
components;
each string is a
component
of the variable.
- continue
-
A builtin command which causes execution of the enclosing
foreach
or
while
loop to cycle prematurely.
Similar to the
continue
command in the programming language C (3.6).
- control-
-
Certain special characters, called
control
characters, are produced by holding down the CONTROL key
on your terminal and simultaneously pressing another character, much like
the SHIFT key is used to produce upper case characters. Thus
control-c
is produced by holding down the CONTROL key while pressing the
`c' key. Usually UNIX prints an caret (^) followed by the
corresponding letter when you type a
control
character (e.g. `^C' for
control-c
(1.8).
- core dump
-
When a program terminates abnormally, the system places an image
of its current state in a file named `core'.
This
core dump
can be examined with the system debugger `adb (1)'
or `sdb (1)' in order to determine what went wrong with the program (1.8).
If the shell produces a message of the form
-
Illegal instruction (core dumped)
(where `Illegal instruction' is only one of several possible
messages), you should report this to the author of the program
or a system administrator,
saving the `core' file.
- cp
-
The
cp
(copy) program is used to copy the contents of one file into another
file.
It is one of the most commonly used UNIX commands (1.6).
- csh
-
The name of the shell
program that this document describes.
- .cshrc
-
The file
.cshrc
in your
home
directory is read by each shell as it begins execution.
It is usually used to change the setting of the variable
path
and to set
alias
parameters which are to take effect globally (2.1).
- cwd
-
The
cwd
variable in the shell holds the
absolute pathname
of the current
working directory.
It is changed by the shell whenever your current
working directory
changes and should not be changed otherwise (2.2).
- date
-
The
date
command prints the current date and time (1.3).
- debugging
-
Debugging
is the process of correcting mistakes in programs and shell scripts.
The shell has several options and variables which may be used
to aid in shell
debugging
(4.4).
- default:
-
The label
default:
is used within shell
switch
statements, as it is in the C language
to label the code to be executed if none of the
case
labels matches the value switched on (3.7).
- DELETE
-
The
DELETE
or
RUBOUT
key on the terminal normally causes an interrupt to be sent to the current job.
Many users change the interrupt character to be ^C.
- detached
-
A command that continues running in the
background
after you logout is said to be
detached.
- diagnostic
-
An error message produced by a program is often referred to as a
diagnostic.
Most error messages are not written to the
standard output,
since that is often directed away from the terminal (1.3, 1.5).
Error messsages are instead written to the
diagnostic output
which may be directed away from the terminal, but usually is not.
Thus
diagnostics
will usually appear on the terminal (2.5).
- directory
-
A structure which contains files.
At any time you are in one particular
directory
whose names can be printed by the command
pwd.
The
chdir
command will change you to another
directory,
and make the files
in that
directory
visible. The
directory
in which you are when you first login is your
home
directory (1.1, 2.7).
- directory stack
-
The shell saves the names of previous
working directories
in the
directory stack
when you change your current
working directory
via the
pushd
command. The
directory stack
can be printed by using the
dirs
command, which includes your current
working directory
as the first directory name on the left (2.7).
- dirs
-
The
dirs
command prints the shell's
directory stack
(2.7).
- du
-
The
du
command is a program (described in `du (1)') which
prints the number of disk blocks is all directories below
and including your current
working directory
(2.6).
- echo
-
The
echo
command prints its arguments (1.6, 3.6).
- else
-
The
else
command is part of the `if-then-else-endif' control
command construct (3.6).
- endif
-
If an
if
statement is ended with the word
then,
all lines following the
if
up to a line starting with the word
endif
or
else
are executed if the condition between parentheses after the
if
is true (3.6).
- EOF
-
An
end-of-file
is generated by the terminal by a control-d,
and whenever a command reads to the end of a file which
it has been given as input.
Commands receiving input from a
pipe
receive an
end-of-file
when the command sending them input completes.
Most commands terminate when they receive an
end-of-file.
The shell has an option to ignore
end-of-file
from a terminal
input which may help you keep from logging out accidentally
by typing too many control-d's (1.1, 1.8, 3.8).
- escape
-
A character `\' used to prevent the special meaning of a metacharacter
is said to
escape
the character from its special meaning.
Thus
-
echo \*
will echo the character `*' while just
-
echo *
will echo the names of the file in the current directory.
In this example, \
escapes
`*' (1.7).
There is also a non-printing character called
escape,
usually labelled
ESC
or
ALTMODE
on terminal keyboards.
Some older UNIX systems use this character to indicate that
output is to be
suspended.
Most systems use control-s to stop the output and control-q to start it.
- /etc/passwd
-
This file contains information about the accounts currently on the
system.
It consists of a line for each account with fields separated by
`:' characters (1.8).
You can look at this file by saying
-
cat /etc/passwd
The commands
finger
and
grep
are often used to search for information in this file.
See `finger (1)', `passwd(5)', and `grep (1)' for more details.
- exit
-
The
exit
command is used to force termination of a shell script,
and is built into the shell (3.9).
- exit status
-
A command which discovers a problem may reflect this back to the command
(such as a shell) which invoked (executed) it.
It does this by returning a non-zero number as its
exit status,
a status of zero being considered
`normal termination'.
The
exit
command can be used to force a shell command script to give a non-zero
exit status
(3.6).
- expansion
-
The replacement of strings in the shell input which contain metacharacters
by other strings is referred to as the process of
expansion.
Thus the replacement of the word `*' by a sorted list of files
in the current directory is a `filename expansion'.
Similarly the replacement of the characters `!!' by the text of
the last command is a `history expansion'.
Expansions
are also referred to as
substitutions
(1.6, 3.4, 4.2).
- expressions
-
Expressions
are used in the shell
to control the conditional structures used in the writing of shell
scripts and in calculating values for these scripts.
The operators available in shell
expressions
are those of the language
C (3.5).
- extension
-
Filenames often consist of a
base
name and an
extension
separated by the character `.'.
By convention, groups of related files often share the same
root
name.
Thus if `prog.c' were a C program, then the object file for this
program would be stored in `prog.o'.
Similarly a paper written with the
`-me'
nroff macro package might be stored in
`paper.me'
while a formatted version of this paper might be kept in
`paper.out' and a list of spelling errors in
`paper.errs' (1.6).
- fg
-
The
job control
command
fg
is used to run a
background
or
suspended
job in the
foreground
(1.8, 2.6).
- filename
-
Each file in UNIX has a name consisting of up to 14 characters
and not including the character `/' which is used in
pathname
building. Most
filenames
do not begin with the character `.', and contain
only letters and digits with perhaps a `.' separating the
base
portion of the
filename
from an
extension
(1.6).
- filename expansion
-
Filename expansion
uses the metacharacters `*', `?' and `[' and `]'
to provide a convenient mechanism for naming files.
Using
filename expansion
it is easy to name all the files in
the current directory, or all files which have a common
root
name. Other
filename expansion
mechanisms use the metacharacter `~' and allow
files in other users' directories to be named easily (1.6, 4.2).
- flag
-
Many UNIX commands accept arguments which are not the names
of files or other users but are used to modify the action of the commands.
These are referred to as
flag
options, and by convention consist of one or more letters preceded by
the character `-' (1.2).
Thus the
ls
(list files) command has an option
`-s' to list the sizes of files.
This is specified
-
ls -s
- foreach
-
The
foreach
command is used in shell scripts and at the terminal to specify
repetition of a sequence of commands while the value of a certain
shell variable ranges through a specified list (3.6, 4.1).
- foreground
-
When commands are executing in the normal way such that the
shell is waiting for them to finish before prompting for another
command they are said to be
foreground jobs
or
running in the foreground.
This is as opposed to
background.
Foreground
jobs can be stopped by signals
from the terminal caused by typing different
control characters at the keyboard (1.8, 2.6).
- goto
-
The shell has a command
goto
used in shell scripts to transfer control to a given label (3.7).
- grep
-
The
grep
command searches through a list of argument files for a specified string.
Thus
-
grep bill /etc/passwd
will print each line in the file
/etc/passwd
which contains the string `bill'.
Actually,
grep
scans for
regular expressions
in the sense of the editors
`ed (1)' and `ex (1)'.
Grep
stands for
`globally find
regular expression
and print' (2.4).
- head
-
The
head
command prints the first few lines of one or more files.
If you have a bunch of files containing text which you are wondering
about it is sometimes useful to run
head
with these files as arguments.
This will usually show enough of what is in these files to let you decide
which you are interested in (1.5).
Head
is also used to describe the part of a
pathname
before and including the last `/' character. The
tail
of a
pathname
is the part after the last `/'. The `:h' and `:t' modifiers allow the
head
or
tail
of a
pathname
stored in a shell variable to be used (3.6).
- history
-
The
history
mechanism of the shell allows previous commands to be repeated,
possibly after modification to correct typing mistakes or to change
the meaning of the command.
The shell has a
history list
where these commands are kept, and a
history
variable which controls how large this list is (2.3).
- home directory
-
Each user has a
home directory,
which is given in your entry
in the password file,
/etc/passwd.
This is the directory which you are placed in when you first login.
The
cd
or
chdir
command with no arguments takes you back to this directory, whose
name is recorded in the shell variable
home.
You can also access the
home directories
of other users in forming
filenames using a
filename expansion
notation and the character `~' (1.6).
- if
-
A conditional command within the shell, the
if
command is used in shell command scripts to make decisions
about what course of action to take next (3.6).
- ignoreeof
-
Normally, your shell will exit, printing
`logout'
if you type a control-d at a prompt of `% '.
This is the way you usually log off the system.
You can
set
the
ignoreeof
variable if you wish in your
.login
file and then use the command
logout
to logout.
This is useful if you sometimes accidentally type too many control-d
characters, logging yourself off
(2.2).
- input
-
Many commands on UNIX take information from the terminal or from
files which they then act on.
This information is called
input.
Commands normally read for
input
from their
standard input
which is, by default, the terminal.
This
standard input
can be redirected from a file using a shell metanotation
with the character `<'.
Many commands will also read from a file specified as argument.
Commands placed in
pipelines
will read from the output of the previous
command in the
pipeline.
The leftmost command in a
pipeline
reads from the terminal if
you neither redirect its
input
nor give it a filename to use as
standard input.
Special mechanisms exist for supplying input to commands in shell
scripts (1.5, 3.8).
- interrupt
-
An
interrupt
is a signal to a program that is generated by typing ^C. (On older versions
of UNIX the RUBOUT or DELETE key were used for this purpose.)
It causes most programs to stop execution.
Certain programs, such as the shell and the editors,
handle an
interrupt
in special ways, usually by stopping what they
are doing and prompting for another command.
While the shell is executing another command and waiting for it
to finish, the shell does not listen to
interrupts.
The shell often wakes up when you hit
interrupt
because many commands
die when they receive an
interrupt
(1.8, 3.9).
- job
-
One or more commands
typed on the same input line separated by `|' or `;' characters
are run together and are called a
job.
Simple commands run by themselves without any `|' or `;' characters
are the simplest
jobs.
Jobs
are classified as
foreground,
background,
or
suspended
(2.6).
- job control
-
The builtin functions that control the execution of
jobs are called
job control
commands. These are
bg, fg, stop, kill
(2.6).
- job number
-
When each job
is started it is assigned a small number called a
job number
which is printed next to the job in the output of the
jobs
command. This number, preceded by a `%' character, can be used as an argument
to
job control
commands to indicate
a specific job (2.6).
- jobs
-
The
jobs
command prints a table showing
jobs that are either running in the
background
or are
suspended
(2.6).
- kill
-
A command which sends a
signal
to a job causing it to terminate (2.6).
- .login
-
The file
.login
in your
home
directory is read by the shell each time you login to UNIX
and the commands there are executed.
There are a number of commands which are usefully placed here,
especially
set
commands to the shell itself (2.1).
- login shell
-
The shell that is started on your terminal when you login is called
your
login shell.
It is different from other shells which you may run (e.g. on
shell scripts)
in that it reads the
.login
file before reading commands from the terminal and it reads the
.logout
file after you logout
(2.1).
- logout
-
The
logout
command causes a login shell to exit.
Normally, a login shell will exit when you hit control-d
generating an
end-of-file,
but if you have set
ignoreeof
in you
.login
file then this will not work and you must use
logout
to log off the UNIX system (2.8).
- .logout
-
When you log off of UNIX the shell will execute commands from
the file
.logout
in your
home
directory after it prints `logout'.
- lpr
-
The command
lpr
is the line printer daemon.
The standard input of
lpr
spooled and printed on the UNIX line printer.
You can also give
lpr
a list of filenames as arguments to be printed.
It is most common to use
lpr
as the last component of a
pipeline
(2.3).
- ls
-
The
ls
(list files) command is one of the most commonly used UNIX
commands.
With no argument filenames it prints the names of the files in the
current directory.
It has a number of useful
flag
arguments, and can also be given the names of directories
as arguments, in which case it lists the names of the files in these
directories (1.2).
- mail
-
The
mail
program is used to send and receive messages from other UNIX
users (1.1, 2.1), whether they are logged on or not.
- make
-
The
make
command is used to maintain one or more related files and to
organize functions to be performed on these files.
In many ways
make
is easier to use, and more helpful than
shell command scripts (3.2).
- makefile
-
The file containing commands for
make
is called
makefile
or
Makefile
(3.2).
- manual
-
The
manual
often referred to is the
`UNIX manual'.
It contains 8 numbered sections with a description of each UNIX
program (section 1), system call (section 2), subroutine (section 3),
device (section 4), special data structure (section 5), game (section 6),
miscellaneous item (section 7) and system administration program (section 8).
There are also supplementary documents (tutorials and reference guides)
for individual programs which require explanation in more detail.
An online version of the
manual
is accessible through the
man
command.
Its documentation can be obtained online via
-
man man
If you can't decide what manual page to look in, try the
apropos(1)
command.
The supplementary documents are in subdirectories of /usr/doc.
- metacharacter
-
Many characters which are neither letters nor digits have special meaning
either to the shell or to UNIX.
These characters are called
metacharacters.
If it is necessary to place these characters in arguments to commands
without them having their special meaning then they must be
quoted.
An example of a
metacharacter
is the character `>' which is used
to indicate placement of output into a file.
For the purposes of the
history
mechanism,
most unquoted
metacharacters
form separate words (1.4).
The appendix to this user's manual lists the
metacharacters
in groups by their function.
- mkdir
-
The
mkdir
command is used to create a new directory.
- modifier
-
Substitutions with the
history
mechanism, keyed by the character `!'
or of variables using the metacharacter `$', are often subjected
to modifications, indicated by placing the character `:' after the
substitution and following this with the
modifier
itself.
The
command substitution
mechanism can also be used to perform modification in a similar way,
but this notation is less clear (3.6).
- more
-
The program
more
writes a file on your terminal allowing you to control how much text
is displayed at a time.
More
can move through the file screenful by screenful, line by line,
search forward for a string, or start again at the beginning of the file.
It is generally the easiest way of viewing a file (1.8).
- noclobber
-
The shell has a variable
noclobber
which may be set in the file
.login
to prevent accidental destruction of files by the `>' output redirection
metasyntax of the shell (2.2, 2.5).
- noglob
-
The shell variable
noglob
is set to suppress the
filename expansion
of arguments containing the metacharacters `~', `*', `?', `[' and `]' (3.6).
- notify
-
The
notify
command tells the shell to report on the termination of a specific
background job
at the exact time it occurs as opposed to waiting
until just before the next prompt to report the termination.
The
notify
variable, if set, causes the shell to always report the termination
of
background
jobs exactly when they occur (2.6).
- onintr
-
The
onintr
command is built into the shell and is used to control the action
of a shell command script when an
interrupt
signal is received (3.9).
- output
-
Many commands in UNIX result in some lines of text which are
called their
output.
This
output
is usually placed on what is known as the
standard output
which is normally connected to the user's terminal.
The shell has a syntax using the metacharacter `>' for redirecting
the
standard output
of a command to a file (1.3).
Using the
pipe
mechanism and the metacharacter `|' it is also possible for
the
standard output
of one command to become the
standard input
of another command (1.5).
Certain commands such as the line printer daemon
p
do not place their results on the
standard output
but rather in more
useful places such as on the line printer (2.3).
Similarly the
write
command places its output on another user's terminal rather than its
standard output
(2.3).
Commands also have a
diagnostic output
where they write their error messages.
Normally these go to the terminal even if the
standard output
has been sent to a file or another command, but it is possible
to direct error diagnostics along with
standard output
using a special metanotation (2.5).
- path
-
The shell has a variable
path
which gives the names of the directories in which it searches for
the commands which it is given.
It always checks first to see if the command it is given is
built into the shell.
If it is, then it need not search for the command as it can do it internally.
If the command is not builtin, then the shell searches for a file
with the name given in each of the directories in the
path
variable, left to right.
Since the normal definition of the
path
variable is
-
path (. /usr/ucb /bin /usr/bin)
the shell normally looks in the current directory, and then in
the standard system directories `/usr/ucb', `/bin' and `/usr/bin' for the named
command (2.2).
If the command cannot be found the shell will print an error diagnostic.
Scripts of shell commands will be executed using another shell to interpret
them if they have `execute' permission set.
This is normally true because a command of the form
-
chmod 755 script
was executed to turn this execute permission on (3.3).
If you add new commands to a directory in the
path,
you should issue
the command
rehash
(2.2).
- pathname
-
A list of names, separated by `/' characters, forms a
pathname.
Each
component,
between successive `/' characters, names a directory
in which the next
component
file resides.
Pathnames
which begin with the character `/' are interpreted relative
to the
root
directory in the filesystem.
Other
pathnames
are interpreted relative to the current directory
as reported by
pwd.
The last component of a
pathname
may name a directory, but
usually names a file.
- pipeline
-
A group of commands which are connected together, the
standard output
of each connected to the
standard input
of the next,
is called a
pipeline.
The
pipe
mechanism used to connect these commands is indicated by
the shell metacharacter `|' (1.5, 2.3).
- popd
-
The
popd
command changes the shell's
working directory
to the directory you most recently left using the
pushd
command. It returns to the directory without having to type its name,
forgetting the name of the current
working directory
before doing so (2.7).
- port
-
The part of a computer system to which each terminal is
connected is called a
port.
Usually the system has a fixed number of
ports,
some of which are connected to telephone lines
for dial-up access, and some of which are permanently
wired directly to specific terminals.
- pr
-
The
pr
command is used to prepare listings of the contents of files
with headers giving the name of the file and the date and
time at which the file was last modified (2.3).
- printenv
-
The
printenv
command is used
to print the current setting of variables in the environment
(2.8).
- process
-
An instance of a running program is called a
process
(2.6).
UNIX assigns each
process
a unique number when it is
started - called the
process number.
Process numbers
can be used to stop individual
processes
using the
kill
or
stop
commands when the
processes
are part of a detached
background
job.
- program
-
Usually synonymous with
command;
a binary file or shell command script
which performs a useful function is often
called a
program.
- prompt
-
Many programs will print a
prompt
on the terminal when they expect input.
Thus the editor
`ex (1)' will print a `:' when it expects input.
The shell
prompts
for input with `% ' and occasionally with `? ' when
reading commands from the terminal (1.1).
The shell has a variable
prompt
which may be set to a different value to change the shell's main
prompt.
This is mostly used when debugging the shell (2.8).
- pushd
-
The
pushd
command, which means `push directory', changes the shell's
working directory
and also remembers the current
working directory
before the change is made, allowing you to return to the same
directory via the
popd
command later without retyping its name (2.7).
- ps
-
The
ps
command is used to show the processes you are currently running.
Each process is shown with its unique process number,
an indication of the terminal name it is attached to,
an indication of the state of the process (whether it is running,
stopped, awaiting some event (sleeping), and whether it is swapped out),
and the amount of CPU time it has used so far.
The command is identified by printing some of the words used
when it was invoked (2.6).
Shells, such as the
csh
you use to run the
ps
command, are not normally shown in the output.
- pwd
-
The
pwd
command prints the full
pathname
of the current
working directory.
The
dirs
builtin command is usually a better and faster choice.
- quit
-
The
quit
signal, generated by a control-\,
is used to terminate programs which are behaving unreasonably.
It normally produces a core image file (1.8).
- quotation
-
The process by which metacharacters are prevented their special
meaning, usually by using the character `' in pairs, or by
using the character `\', is referred to as
quotation
(1.7).
- redirection
-
The routing of input or output from or to a file is known
as
redirection
of input or output (1.3).
- rehash
-
The
rehash
command tells the shell to rebuild its internal table of which commands
are found in which directories in your
path.
This is necessary when a new program is installed in one of these
directories (2.8).
- relative pathname
-
A
pathname
which does not begin with a `/' is called a
relative pathname
since it is interpreted
relative
to the current
working directory.
The first
component
of such a
pathname
refers to some file or directory in the
working directory,
and subsequent
components
between `/' characters refer to directories below the
working directory.
Pathnames
that are not
relative
are called
absolute pathnames
(1.6).
- repeat
-
The
repeat
command iterates another command a specified number of times.
- root
-
The directory
that is at the top of the entire directory structure is called the
root
directory since it is the `root' of the entire tree structure of
directories. The name used in
pathnames
to indicate the
root
is `/'.
Pathnames
starting with `/' are said to be
absolute
since they start at the
root
directory.
Root
is also used as the part of a
pathname
that is left after removing
the
extension.
See
filename
for a further explanation (1.6).
- RUBOUT
-
The RUBOUT or DELETE
key is often used to erase the previously typed character; some users
prefer the BACKSPACE for this purpose. On older versions of UNIX
this key served as the INTR character.
- scratch file
-
Files whose names begin with a `#' are referred to as
scratch files,
since they are automatically removed by the system after a couple of
days of non-use, or more frequently if disk space becomes tight (1.3).
- script
-
Sequences of shell commands placed in a file are called shell command
scripts.
It is often possible to perform simple tasks using these
scripts
without writing a program in a language such as C, by
using the shell to selectively run other programs (3.3, 3.10).
- set
-
The builtin
set
command is used to assign new values to shell variables
and to show the values of the current variables.
Many shell variables have special meaning to the shell itself.
Thus by using the
set
command the behavior of the shell can be affected (2.1).
- setenv
-
Variables in the environment `environ (5)'
can be changed by using the
setenv
builtin command (2.8).
The
printenv
command can be used to print the value of the variables in the environment.
- shell
-
A
shell
is a command language interpreter.
It is possible to write and run your own
shell,
as
shells
are no different than any other programs as far as the
system is concerned.
This manual deals with the details of one particular
shell,
called
csh.
- shell script
-
See
script
(3.3, 3.10).
- signal
-
A
signal
in UNIX is a short message that is sent to a running program
which causes something to happen to that process.
Signals
are sent either by typing special
control
characters on the keyboard or by using the
kill
or
stop
commands (1.8, 2.6).
- sort
-
The
sort
program sorts a sequence of lines in ways that can be controlled
by argument
flags
(1.5).
- source
-
The
source
command causes the shell to read commands from a specified file.
It is most useful for reading files such as
.cshrc
after changing them (2.8).
- special character
-
See
metacharacters
and the
appendix to this manual.
- standard
-
We refer often to the
standard input
and
standard output
of commands.
See
input
and
output
(1.3, 3.8).
- status
-
A command normally returns a
status
when it finishes.
By convention a
status
of zero indicates that the command succeeded.
Commands may return non-zero
status
to indicate that some abnormal event has occurred.
The shell variable
status
is set to the
status
returned by the last command.
It is most useful in shell commmand scripts (3.6).
- stop
-
The
stop
command causes a
background
job to become
suspended
(2.6).
- string
-
A sequential group of characters taken together is called a
string.
Strings
can contain any printable characters (2.2).
- stty
-
The
stty
program changes certain parameters inside UNIX which determine
how your terminal is handled. See `stty (1)' for a complete description (2.6).
- substitution
-
The shell implements a number of
substitutions
where sequences indicated by metacharacters are replaced by other sequences.
Notable examples of this are history
substitution
keyed by the
metacharacter `!' and variable
substitution
indicated by `$'.
We also refer to
substitutions
as
expansions
(3.4).
- suspended
-
A job becomes
suspended
after a STOP signal is sent to it, either by typing a
control-z
at the terminal (for
foreground
jobs) or by using the
stop
command (for
background
jobs). When
suspended,
a job temporarily stops running until it is restarted by either the
fg
or
bg
command (2.6).
- switch
-
The
switch
command of the shell allows the shell
to select one of a number of sequences of commands based on an
argument string.
It is similar to the
switch
statement in the language C (3.7).
- termination
-
When a command which is being executed finishes we say it undergoes
termination
or
terminates.
Commands normally terminate when they read an
end-of-file
from their
standard input.
It is also possible to terminate commands by sending them
an
interrupt
or
quit
signal (1.8).
The
kill
program terminates specified jobs (2.6).
- then
-
The
then
command is part of the shell's
`if-then-else-endif' control construct used in command scripts (3.6).
- time
-
The
time
command can be used to measure the amount of CPU
and real time consumed by a specified command as well
as the amount of disk i/o, memory utilized, and number
of page faults and swaps taken by the command (2.1, 2.8).
- tset
-
The
tset
program is used to set standard erase and kill characters
and to tell the system what kind of terminal you are using.
It is often invoked in a
.login
file (2.1).
- tty
-
The word
tty
is a historical abbreviation for `teletype' which is frequently used
in UNIX to indicate the
port
to which a given terminal is connected. The
tty
command will print the name of the
tty
or
port
to which your terminal is presently connected.
- unalias
-
The
unalias
command removes aliases (2.8).
- UNIX
-
UNIX is an operating system on which
csh
runs.
UNIX provides facilities which allow
csh
to invoke other programs such as editors and text formatters which
you may wish to use.
- unset
-
The
unset
command removes the definitions of shell variables (2.2, 2.8).
- variable expansion
-
See
variables
and
expansion
(2.2, 3.4).
- variables
-
Variables
in
csh
hold one or more strings as value.
The most common use of
variables
is in controlling the behavior
of the shell.
See
path,
noclobber,
and
ignoreeof
for examples.
Variables
such as
argv
are also used in writing shell programs (shell command scripts)
(2.2).
- verbose
-
The
verbose
shell variable can be set to cause commands to be echoed
after they are history expanded.
This is often useful in debugging shell scripts.
The
verbose
variable is set by the shell's
-v
command line option (3.10).
- wc
-
The
wc
program calculates the number of characters, words, and lines in the
files whose names are given as arguments (2.6).
- while
-
The
while
builtin control construct is used in shell command scripts (3.7).
- word
-
A sequence of characters which forms an argument to a command is called
a
word.
Many characters which are neither letters, digits, `-', `.' nor `/'
form
words
all by themselves even if they are not surrounded
by blanks.
Any sequence of characters may be made into a
word
by surrounding it
with `'' characters
except for the characters `'' and `!' which require special treatment
(1.1).
This process of placing special characters in
words
without their special meaning is called
quoting.
- working directory
-
At any given time you are in one particular directory, called
your
working directory.
This directory's name is printed by the
pwd
command and the files listed by
ls
are the ones in this directory.
You can change
working directories
using
chdir.
- write
-
The
write
command is an obsolete way of communicating with other users who are logged in to
UNIX (you have to take turns typing). If you are both using display
terminals, use talk(1), which is much more pleasant.