sh \- a shell (command interpreter)
is a command interpreter.
It arranges and interprets command lines and the contents of command files.
It is a modification of the standard shell
and almost completely upward compatible therewith.
The intent, in working on a new shell,
is to provide an environment which is more easily tailored to the
wishes of each individual user.
Most new features of this shell,
Later versions of this shell may include improvements to the command
language of the shell and allow more easy repetition of commands.
The intent here is to make the command language more resemble a
high-level language \- C being the natural choice for
and to provide some means of repeating modified commands without retyping,
The eventual goal is a C\-shell,
(or ``seashell'' if you prefer.)
this shell is currently available as
We discuss the major features of the shell beginning with the objects
then the lexical structure of the shell input,
details on command execution,
and finally a list of the built-in commands with a simple description of each.
This documentation is neither fully polished nor devoid of forward references.
was a ``working'' version of the new
which became useful when the completion of
It is hoped that this documentation will serve as a reference for
users who have lived, to this point, by word-of-mouth information.
of the shell world are the
which consists of specially named and initialized variables.
The variables in the argument list have numeric names, e.g. `1' and `2'.
The other variables have alphabetic names, composed of upper and
Variable names may be up to 20 characters long.
There is a distinction between a variable existing and not existing,
akin to a variable being on the
Initially, no variables exist;
in shell terminology, no variables are
Variables have string values only;
some numeric operations are defined on variables,
but the representation of variables is always as a string.
Some variables have special meaning to the shell;
is the process id of the shell, set to a string with this value
when the shell is created.
These variables have, however, no special status.
They may be manipulated as any other variables are,
with the caveat being that these manipulations may directly affect
the behavior of the shell.
One other point to be noted is that some of the built-in variables
are essentially `toggles';
that is, the shell cares only if they are set or not,
The standard way to set such a variable is to set it to be the null
The primary lexical structuring of the input to the shell is the line.
A new-line character is thus normally of syntactic significance, although
it may be escaped with a `\e' as described below.
The most fundamental delimiters for the shell are the blank and the
tab character, generated by a control-i.
There are also a number of characters which have special significance
as they define tokens which are part of the command language of the shell:
`>' and `<' which denote input and output redirection,
`(' and `)' which are used to delimit command lists,
`;' which is used to separate commands for sequential execution,
and `|' and `^' which are completely equivalent ways of specifying a
The ways in which these are used in construction of shell commands
will be discussed in the next section.
At the syntactic level, there is also a
.it "parameter substitution"
facility, which can be used to substitute variables.
Parameter substitution is introduced by the character `$'
and has several different forms, each of which yields zero or more
characters into the input stream replacing it.
We describe each such construct in turn.
$number Substitutes the number'th argument in the currently
positioned argument list.
The accessing of the argument will be described later.
$* Substitutes all arguments in the current argument list,
starting at the first `$1';
successive arguments are separated by blanks.
${name} Substitutes the value of the shell variable
The second form can be used when this construct is immediately
$$ Equivalent to `${pid}'.
${name?str1:str2} Substitutes
if name is set else substitutes
Currently only quoting with `\e' works correctly within
In particular, `$' constructs and quoting via `\'' and `"' within
these strings is unreliable as it is badly implemented.
${name:default} Substitutes the value of
if this variable is set, else substitutes
${name?str} Substitutes the string
is set, else substitutes nothing.
Whenever a paramter is being substituted a slightly different effect
occurs if the `$' is immediately followed by a `.'.
In this case, any substitution from parameters trims suffices from
Thus if `$0' gives `a.out', then `$.0' will give `a',
and if `$prog' would give `foo.p' then `$.prog' would give `foo'.
Also if the `$' character is not followed by any character described
above then that character is returned.
special characters to prevent their special meaning.
Before describing the various ways to do this, we should note that
the characters `[', `*' and `?' have special meaning in command
contexts where they cause
.it "filename expansion,"
a kind of pattern matching of an lexical token against file names.
These characters also often need to be quoted.
The most simple kind of quoting is that with the character `\e',
thus `\e>' is the same as the character `>',
but will not be recognized as a syntactic metacharacter for output
There is a way to quote longer strings using either the delimiter
could be used to prevent the spaces and `*'s from having their
It should be noted that no quoting, expansion or substitution of
any kind occurs within `\''s or `"'s, and that the quoting
must terminate before an end of line.
It is also possible in the shell to escape the newline character with
a `\e', this causing the newline to be effectively replaced by a blank.
.bd "Syntactic structure."
The syntactic structure of the input to
is essentially the same as that to
The fundamental component of a command is a
which consists of one or more commands separated by the character
`|' or `^', with the separator optionally followed by the character `*',
Each command in the pipeline has its standard output connected to the
standard input of the next.
The forms with the character `*' cause the diagnostic output to go through
the pipe with the standard output.
More than one pipeline may be given on a single line if they
are separated by the sequential execution separator `;'.
The separator `&' termiates such a list of commands and causes
the entire list to be executed without waiting for termination.
is set to the process id of the shell co-ordinating the execution
of the command list, and this number is typed on the shells diagnostic output.
When the command terminates,
Finally, the basic commands are composed of a command name and
a list of (zero or more) arguments.
There may also be input or output redirection specifiers of the form
`<', `>' or `>>', possibly followed by `*', and then a parameter
The `*' here, as in the pipe specifiers above, specifies that diagnostic
output is to be redirected with standard output (and is thus not
The form `< name' causes the standard input to be taken from the file
which is first subjected to
as described below if it contains any of the characters
The form `> name' causes the standard output to be put in the file
which is created, or truncated to length zero before execution begins
The form `>> name' is like `> name' but output is put at the end of
It should be noted that when a pipeline is executed in the background,
the first element of the pipeline will take input from
unless the input is otherwise redirected.
A final syntactic structuring is provided by parentheses `(' and `)'.
A command may be given as a ny of the forms given above thus enclosed
and participate in a pipeline.
(date; time; echo "***") | lpr
and echoes the character string `***' to the line printer daemon
When a command is to be executed,
the shell first examines the command name to see if it is a name
If it is not, then the shell will see if the name is actually
If it is, then the process starts over again,
wiht the command name replaced by its
This process of alternately checking for built-in commands and for
aliases will continue up to 100 times to allow multiple aliases.
If this process terminates with the recognition of a built-in command
then that command will be performed.
If not, then the shell will attempt to find the resulting command in the
directories in its search path as defined by the value of the
This variable consists of a sequence of directory names separated by
where here the initial `\-' signals that the first directory to
be searched is `.', which is the same as the null string.
After this, we are to search the directories `/bin' and `/usr/bin'
is not set, then the value `\-' is assumed, causing
only the current directory to be searched.
If the given command name includes the character `/',
then it will be executed if and only if the path includes a null
directory specification, and never from other prefixes in the path.
Thus even if there is a `/bin/bin/date',
`bin/date' will not find it with the default path.
If the command name contains `*', '?' or `[',
as described below and will be interpreted only
relative to the current directory or as a full path name.
There is a general process of
applied to the arguments to the command.
In this process the characters `*', `?' and `[' have special meaning.
The character `*' will match any sequence of characters in a file name,
the character `?' any single character,
`[chars]' will match any of the characters in
within chars standing for all characters between and including `x' and `y'.
This process applies to arbitrary path names, and is subject to two
First, each `/' in such a path name must appear explicitly in the
pattern \- `/'s are never matched by `*', `/' or a `[' construct.
Similarly, if the first character of a file name is the character
`.', it must be matched explicitly with a character `.' in the pattern.
If, during command argument expansion, some arguments specify
filename expansion, but none of these arguments matches any file
name, then a diagnostic ``No match'' will be given and the command
A special variant of this filename substitution occurs in input
redirect filenames, command names, and arguments to the built-in
Here the expansion must result in exactly one filename or a diagnostic
will be printed indicating that the given pattern is ``Ambiguous''.
If the shell finds a file which is executable but is not recognized
by the system as an object file, then it will be examined to see if
it is appropriate to be used as a shell script or by one of the
interpreters the shell knows about.
If the first word of the file contains the magic number of one of
the interpreters, e.g. 0404 octal for the Pascal interpreter
then this interpreter will be forked with the arguments shifted
to the right, the name of the file becoming the first argument.
If the first word of the file does not indicate any of the interpreters,
characters then a shell will be invoked as an interpreter.
The path name for this shell may be specified using the
When a command terminates, if it terminates abnormally, a message
will be printed indicating the cause of abnormal termination.
If the command was not the one being waited for, i.e. if a background
process started with `&' terminates abnormally,
its process number will also be given.
Finally, a time statistics line may be printed at command termination.
This is described with the
.bd "Predefined and special variables."
The following variables have special meaning to the shell and
affect its behavior or are set as side effects of various commands.
home Set to the users home directory as given in the
Usually the directory where the user logs in, this is the default
nargs Maintained as the number of arguments in the current argument
nice If given a numeric value, each executed command will be
to this priority immediately before execution.
path Specifies the search path for command executions as described
pcs The process number of the last command started with `&'.
Unset when this command completes.
pid The process number of the shell; used in `$$'.
prompt The prompt which preceded each command line interactively.
If the shell is not interactive, then this variable is not set.
shell The shell which is the default interpreter for executable
files not recognized by the system.
Defaults to `/usr/pascal/sh', the current home of
time When set, causes a command statistic line to be given following
This line includes the number of user cpu seconds, system cpu seconds,
real time in hours minutes and seconds, and
the machine utilization over this period expressed as a percentage.
If given a numeric value,
statistics will be given only for commands requiring more than
this many total cpu seconds.
.bd "Start up processing."
When a new shell is created it first sets the
variables and sets up any default aliases and interpreters.
(Current default \fIalias\fR is ``time'' for ``tyme'',
interpreter is ``/bin/px'' on value 0404.)
The shell then process the command line arguments as follows:
\fB\-V\fR Causes the shell to be
like \fB\-v\fR, but even when processing
\fB\-v\fR Causes the shell to be verbose; command input
is echoed to the output with indication of the arguments which
were substituted for parameters with the `$' mechanisms;
such substitutions are bracketed with `[' and `]' for visibility.
\fB\-c\fR Causes the shell to take as input the contents
of the immediately following string.
\fB\-t\fR Causes the shell to read exactly one line of
input from its standard input.
\fB\-i\fR Causes the shell to be interactive:
the remaining arguments are \fInot\fR interpreted as a file to
be executed and parameters,
and the shell ignores interrupts and quits and prompts
Shells which have standard input and output teletypes
also are interactive in the sense that they ignore interrupts and quits.
flag is given, then the shell does not prompt, i.e.
argument is taken to be the name of a file containing commands to be executed.
This argument becomes available as the 0'th parameter during
interpretation, i.e. `$0'.
The remaining arguments become the positional parameters,
The number of such positional parameters will be given by the variable
These parameters may be manipulated by
After setting up all of this, the shell will read commands from
in the user's home directory.
This file is typically used to set aliases and variables
that the user wishes and also to change the value of
If the shell is a login shell,
defined as having been invoked with a name which started with `\-',
the shell will then read commands from the file `.login' in the same directory.
Shells normally terminate when they receive an end-of-file from their
login shells will print ``logout'' when this occurs and execute the commands
from the file `.logout' in the home directory.
The home directory for the purpose of finding `.logout' is independent
of the current value of the variable
The following commands are built into the shell.
Input and output redirections have no effect on these commands,
Note also that since the command
is not done within the shell, it cannot, in general,
be used to qualify a built-in command.
In general, therefore, the shell control structure must be used like
abort Terminate abnormally.
Useful only for shell debugging or fits of frenzy.
alias Specify an alias for a command.
When given two arguments the first argument is given alias the second
When given one argument the alias for that argument will be given.
When given no arguments all aliases are given.
If no argument is given change to the directory in the variable
The argument may contain the metacharacters `*', `?' and `['
which are interpreted as for executed commands.
This is the only built-in function which takes such arguments.
interp Specify interpreters.
except that the first argument is the value of the first word of
a file for this interpreter, i.e. its magic number,
and the second is the name of the interpreter.
logout Same as a control-d.
noquit Causes the shell to ignore \s-2QUIT\s0 signals.
quit Causes the shell to not ignore \s-2QUIT\s0 signals
for the purposes of debugging.
rewind Causes the shell to reset the argument list to the state
at entry, reversing the effect of all
set Give one or more variables or parameters new values.
With no arguments types the names and values of all variables.
The simples kind of set is to set a variable `on', i.e. to
To do this you can just mention its name, i.e.
It is also possible to give variables string values by specifying
the value after an `=', thus
in the same was as the previous example, and also changes
Finally, it is possible to do arithmetic in the
Operators available are `+=', `\-=', `*=', `/=', `|=',
`&=', `%=', `=', `++' and `\-\-'.
increments the value of variable
and then multiples the value of the variable
by the value of the variable
Note that the operators `|' and `&' must be quoted, i.e.:
One final operator is `@' which is equivalent to an
All of these operators except `@' may be applied to parameters, e.g.:
shift Causes the argument list to be right shifted, argument 2
becoming argument 1, etc.
May be given a count, possibly negative, for multiple right or
left shifts, i.e. `shift \-1' for a left shift.
tyme An internal version of \fItime\fR corresponding to ``set time''
for the course of the command.
Does not work correctly for `&' processes.
Note that \fItime\fR is aliased to
unalias Given a parameter, removes that alias from the list of aliases.
uninterp Like unalias for interpreters, takes the magic number and
removes the corresponding entry.
unset Removes the specified variables.
wait Wait for all processes to terminate,
or for the specified process to terminate.
/etc/htmp home directory data base
/etc/passwd home directory data when not in \fIhtmp\fR
\&.login start-up for login shells
\&.logout prologue for login shells
\&.profile beginning script for all shells
/dev/null source of end-of-file
sh (I), chdir (I), chdir (II), if (I), goto (I)
As this is an experimental shell, there are probably several.
Mostly, the design has a lot of rough edges and the new features
don't always ``like'' each other.
Some of them can't be successfully mixed.