Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

csh(1)

test(1)

execve(2)

environ(7)

SH(1)  —  UNIX Programmer’s Manual

NAME

sh, for, case, if, while, :, ., break, continue, cd, echo, eval, exec, exit, export, hash, login, pwd, read, readonly, return, set, shift, test, times, trap, type, ulimit, umask, unset, wait − command language

SYNOPSIS

sh [ −abcefhiknrstuvx | -- ] [ +abcefhiknrstuvx ] [ arg ] ... 
rsh [ flags ] [ arguments ]

DESCRIPTION

Sh is a command programming language that executes commands read from a terminal or a file.  See “Invocation” for the meaning of arguments to the shell.  Sh is the recommended interface for writing “command scripts” and is a fairly widely available interactive interface.  Unlike csh(1) sh does not provide job control facilities to manage simultaneous execution of multiple commands. 

Commands

A simple command is a sequence of non blank words separated by blanks (a blank is a tab or a space).  The first word specifies the name of the command to be executed.  Except as specified below the remaining words are passed as arguments to the invoked command.  The command name is passed as argument 0 (see execve(2)). The value of a simple command is its exit status if it terminates normally or status+128 (200 octal) if it terminates abnormally.  In this case the status is the number of the signal which caused the termination − see sigvec(2) for a list of signal values.  Exit status values are determined by the individual command, the only firm rule being that zero means success.

A pipeline is a sequence of one or more commands separated by |.  The standard output of each command but the last is connected by a pipe(2) to the standard input of the next command.  Each command is run as a separate process, all the commands run concurrently; the shell waits for the last command to terminate.  The exit status of the pipeline is the exit status of the last command in the pipeline.

A list is a sequence of one or more pipelines separated by ;, &, && or || and optionally terminated by ; or &.  Within this group of four symbols ; and & have equal precedence which is lower than that of && and ||.  && and || also have equal precedence.  A semicolon causes sequential execution (left to right); an ampersand causes the preceding pipeline to be executed without waiting for it to finish.  The symbols && and || also cause sequential execution, however the list following one of these symbols is only executed if the preceding pipeline returns a zero (&&) or non-zero (||) value.  Newlines may appear in a list, instead of semicolons, to delimit commands.

A command is either a simple command or one of the following.  The value returned by a command is that of the last simple command executed in the command. 

for name [in word ...] do list done
Each time a for command is executed name is set to the next word in the for word list.  If in word ...  is omitted, in $@ is assumed.  Execution ends when there are no more words in the list. 

case word in [pattern [ | pattern ] ... ) list ;;] ... esac
A case command executes the list associated with the first pattern that matches word.  The form of the patterns is the same as that used for file name generation except that no special interpretation is place on / or /.  so these may be matched by ∗ or ?  in the pattern. 

if list then list [elif list then list] ... [else list] fi
The list following if (the test) is executed and if it returns zero the list following then is executed.  Otherwise, the list following elif is executed and if its value is zero the list following then is executed.  Failing that the else list is executed.  If the test fails but no else clause is present the if commands returns a zero exit status, however this is not portable.  The effect of the −e flag (see the set command below) is suspended while the test is executed, again, this is not portable. 

while list [do list] done
A while command repeatedly executes the while list and if its value is zero executes the do list; otherwise the loop terminates.  The value returned by a while command is that of the last executed command in the do list. until may be used in place of while to negate the loop termination test.  As with if the −e flag is ignored during the test.  If no commands are executed the while command returns a 0 exit status. 

( list )
Execute list in a subshell. 

{ list ;}
list is simply executed.  The ; must not be omitted, but it can be replaced by a newline.  (The } must be parsed by the shell as a command.) 

name() command
This defines a built-in command called name; such commands are called functions. The existing built-in commands cannot be redefined (this is enforced silently by executing the built-in command in preference to the function).  The new function can be used anywhere a simple command may appear.  When it is executed the body of the function defined by command is executed with the positional parameters $n set to the arguments of the function - see the “Execution” section below.  Command will normally not be one of the above forms, rather than just a simple command.  Frequently the form:

{ list ;}

is used to allow a sequence of commands to be executed. 

The following words are only recognized as the first word of a command and when not quoted. 

if then else elif fi case in esac for while until do done { }

Comments

Comments may be included in the input to the shell using the # character at the start of a word.  The word and all following words to the end of the line are ignored by the shell.  The end of the line is recognised even if escaped using \. 

Command substitution

The standard output from a command enclosed in a pair of back quotes (``) (the ISO-8859 grave accent character) may be used as part or all of a word or as a series of words; trailing newlines are removed, embedded newlines are treated as space characters (although they remain as newline characters if quoted within a word).  This is because the shell separates the input into words after performing the substitution. 

Parameter substitution

The character $ is used to introduce substitutable parameters, either positional parameters or keyword parameters, known as variables. Positional parameters may be assigned values by set and have names which are single digits (0-9).  The initial value of the positional parameters is defined by the successive words of the command which invoked the shell or function, with $0 being the shell or function name.  Variables may be set and created by writing

name=value [ name=value ] ... 

The = must immediately follow the name; they must be part of the same word.  The value is not scanned for pattern matching characters ∗ or ?. 

Variable and function names occupy the same name space − a name cannot be used for both a variable and a function at the same time (creating a variable of a given name will destroy the function and vice versa). 

Parameter substitution is performed according to the format of the substitutable parameter, a parameter is a sequence of ASCII letters, digits or underscores (a name), a digit, or any of the characters ∗ @ # ? − $ !. Notice that characters in the upper half of the ISO-8859 character set, although they may correspond to alphabetic characters, are not supported within names.

${parameter}
The value, if any, of the parameter is substituted. The braces are required only when parameter is followed by a letter, digit, or underscore that is not to be interpreted as part of its name.  If parameter is a digit, it is a positional parameter.  If parameter is ∗ or @ then all the positional parameters, starting with $1, are substituted separated by spaces.  $0 is set from argument zero when the shell is invoked. 

${parameter:−word}
If parameter is set and is not the empty string, substitute its value; otherwise substitute word. 

${parameter:=word}
If parameter is not set or is the empty string, set it to word; the value of the parameter is then substituted. Positional parameters may not be set in this way.

${parameter:?word}
If parameter is set and is not the empty string, substitute its value; otherwise, print word and exit from the shell or, for an interactive shell, return control to the user.  If word is omitted the standard message:

parameter: parameter null or not set

is printed. 

${parameter:+word}
If parameter is set and is not the empty string, substitute word; otherwise substitute nothing.

In the above word is not evaluated unless it is to be used as the substituted string.  (So that, for example, “echo ${d−´pwd´}” will only execute pwd if d is unset.) 

The colon may be omitted from the above forms in which case the shell does not check a set parameter to ensure that it is not set to the empty string. 

The following parameters are automatically set by the shell:

# The number of positional parameters in decimal. 

− Options supplied to the shell on invocation or by set.  The options are a list of lower case latters (see the set command below).  There is no leading −. 

?  The value returned by the last executed command in decimal.  This is not set as a result of background commands (run with a trailing &) terminating. 

$ The process number of this shell. 

!  The process number of the last background command invoked. 

The following parameters are used but not set by the shell. 

HOME The default argument (home directory) for the cd command. 

PATH The search path for commands (see the “Execution” subsection).  This may not be changed if the shell is running with the −r option. 

CDPATH The search path for the cd command − see the “Special Commands” subsection. 

MAIL If this variable is set to the name of a mail file and the MAILPATH variable is not set, the shell informs the user of the arrival of mail in the specified file.  This is done by checking the length of the file at intervals specified by MAILCHECK, so the facility can be used to detect length increase of any file.  The check is only performed for interactive shells. 

MAILCHECK
This variable gives the delay in seconds between each check on the files specified by MAIL or MAILPATH.  The default value (if the variable is not set) is 600 seconds.  If the variable is set to 0 the shell will check before each primary prompt is displayed. 

MAILPATH
This variable may be set to a colon separated list of file names. If set an interactive shell will check all of these files at intervals specified by MAILCHECK and inform the user if the length of any increases.  If the file name is followed by a % character then a message that message will be printed if the file length increases, otherwise the default message “you have mail” will be printed. 

PS1 Primary prompt string, by default ’$ ’. 

PS2 Secondary prompt string, by default ’> ’. 

IFS Internal field separators, normally space, tab, and newline. 

SHELL Normally this variable holds the name of the shell to use for interactive commands.  When sh starts it scans its environment for this name, if the name exists and its filename part contains an “r” character the shell becomes a restricted shell, as though the −r option was specified on the command line − see the “Invocation” subsection below. 

Notice that this implementation of the shell does not use the facilities of the native language system, in particular the variables LANG,LC_∗ and NLSPATH are not handled. 

Blank interpretation

After parameter and command substitution, any results of substitution are scanned for internal field separator characters (those found in $IFS) and split into distinct arguments where such characters are found.  As a result explicit null arguments ("" or ´´) are retained whereas the results of parameter substitutions are indistinguishable from the indentical characters typed directly into the command line − in particular if a parameter substitution results in insertion of no characters the preceding and following characters appear immediately adjacent. 

File name generation

Following substitution, each command word is scanned for the characters ∗, ?  and [. If one of these characters appears, the word is regarded as a pattern. The word is replaced with sorted file names that match the pattern.  If no file name is found that matches the pattern, the word is left unchanged.  The character .  at the start of a file name or immediately following a /, and the character /, must be matched explicitly.  The order into which the names are sorted is determined by the ASCII value of the corresponding characters.  Byte values in the range 128-255 are sign extended to give the corresponding negative values (this is not portable). 

∗ Matches any string, including the null string. 

?  Matches any single character. 

[...] Matches any one of the characters enclosed.  A pair of characters separated by − matches any character with ASCII value between the pair (inclusive of the pair).  If the first character is a !  the sense of the pattern is inverted and it matches any character which is not given. 

Quoting

The following characters have a special meaning to the shell and cause termination of a word unless quoted. 

;   &   (   )   |   <   >   newline   space   tab

A character may be quoted by preceding it with a \ except that the pair \<newline> is ignored.  No special interpretation is made for a quoted character, thus it becomes part of the word which is made up of the adjacent characters.  All characters enclosed between a pair of single quote marks (´´), except a single quote itself, are quoted.  Inside double quotes ("") parameter and command substitution occurs and \ must be used to quote the characters \ " and $ and may also be used to quote ´ (thus \´ will be replaced by ´, however a ´ on its own will not be interpreted specially).  Also the parameter substitution $@ is specially interpreted, so that, although "$∗" is equivalent to "$1 $2 ..." "$@" is equivalent to "$1" "$2" ... .  Thus, within double quotes, $@ itself is replaced by $1" "$2" ... "$n. 

Prompting

When used interactively, the shell prompts with the value of PS1 before reading a command.  If at any time a newline is typed and further input is needed to complete a command, the secondary prompt ( PS2 is issued. 

Input and Output

Before a command is executed its input and output may be redirected using a special notation interpreted by the shell.  The following may appear anywhere in a simple command or may precede or follow a command and are not passed on to the invoked command.  Substitution and pattern matching occur before word or digit is used. 

<word
Use file word as standard input (file descriptor 0). 

>word
Use file word as standard output (file descriptor 1).  If the file does not exist, it is created; otherwise it is truncated to zero length. 

>>word
Use file word as standard output.  If the file exists, output is appended (by seeking to the end); otherwise the file is created. 

<<[−]word
The shell input is read up to a line the same as word, or end of file. The resulting characters become the standard input.  If any character of word is quoted, no interpretation is placed upon the characters of the document; otherwise, parameter and command substitution occurs: \newline is removed from the input, and \ must be used to quote the characters \ $ ´ and the first character of word if it appears as a line of input.  In this last case the \ will not be removed from the input. 

<&digit
The standard input is duplicated from file descriptor digit; see dup(2). Similarly for the standard output using >&digit. 

<&− The standard input is closed.  Similarly for the standard output using >−. 

If one of the above is preceded by a digit, the file descriptor created is that specified by the digit (instead of the default 0 or 1).  For example,

... 2>&1

causes file descriptor 2 to be a duplicate of file descriptor 1. 

Such redirections are interpreted from left to right, each taking effect immediately.  Thus the order of redirections is significant if the & notation is used − the file descriptor to be duplicated (to the right of the &) must be corrected set up before the & redirection.  This behaviour can be used to swap file descriptors (using an intermediate descriptor) if desired.   Notice that the notation imposes a limit (0-9) on the number of file descriptors which can be redirected, this is not normally a problem as no standard program accesses descriptors beyond 2. 

If a command is followed by & then the default standard input for the command is the empty file (/dev/null). Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input output specifications.

Redirection of output is not allowed in the restricted shell. 

Environment

The environment is a list of name-value pairs that is passed to an executed program in the same way as a normal argument list; see execve(2) and environ(7). The shell interacts with the environment in several ways. On invocation, the shell scans the environment and creates a parameter for each name found, giving it the corresponding value.  Executed commands inherit the same environment.  If the user modifies the values of these parameters or creates new ones, none of these affects the environment unless the export command is used to bind the shell’s parameter to the environment.  The environment seen by any executed command is thus composed of any unmodified name-value pairs originally inherited by the shell, plus any modifications or additions, all of which must be noted in export commands. 

The environment for any simple command may be augmented by prefixing it with one or more assignments to parameters. Thus these two lines are equivalent

TERM=450 cmd args
(export TERM; TERM=450; cmd args)

If the −k flag is set, all keyword arguments are placed in the environment, even if the occur after the command name.  In the following the first echo prints “a=b c”, the second “c”:

echo a=b c
set −k
echo a=b c

Signals

The INTERRUPT and QUIT signals for an invoked command are ignored if the command is followed by &; otherwise signals have the values inherited by the shell from its parent.  (But see also the trap command below).  Job control signals (SIGTSTP, SIGTTIN, and SIGTTOU) retain the handling which they have on entry to the shell − they are either ignored if the shell executes in an environment without job control facilities or the default action (stopping the shell) will be in place if process management facilities are available (for example from csh(1)). The trap command cannot be used to intercept these signals. 

Most signals which were not ignored on entry to the shell cause the shell to exit if received directly by the shell.  Some, such as SIGWINCH and SIGCONT are left with their default action − any signal which defaults to being discarded (see sigvec(2)) will retain the default action unless trapped using the trap command.  Other signals are trapped and either cause control to return to the top (interactive) level in the shell (a non-interactive shell will exit) or cause the shell to exit.  Normally a signal which corresponds to a serious error in a program and would cause a core dump to be produced causes the shell to exit, other signals just cause return to the top level. 

Execution

Each time a command is executed the above substitutions are carried out.  If the command name matches one of the “Special Commands” below then that command is executed, else if the command name matches a function the body of that function is executed (and so on, recursively).  If neither of these cases apply a new process is created and an attempt is made to execute the command via an execve(2).

The variable PATH defines the search path for the directory containing the command.  Each alternative directory name is separated by a colon (:).  The default path is :/usr/bin although this is almost invariably set by the process which executed the shell.  If the command name contains a /, the search path is not used; although the restricted shell will not execute the command in this case.  Otherwise, each directory in the path is searched for an executable file.  If the file has execute permission but is not an a.out(5) file, it is assumed to be a file containing shell commands. A subshell (i.e., a separate process) is spawned to read it. A parenthesized command is also executed in a subshell.

To speed up command location the place where each executed command is located is remembered by the shell.  If the path to the command is relative to the current directory this information will be discarded when the current directory changes (using cd).  Otherwise the information is discarded when the PATH variable is changed or when explicitly requested using hash -r.  This means that, if a new command is added to a directory on the shell PATH ahead of the location of an old command of the same name the new command will not be noticed by the shell until it resets its command location information. 

Special Commands

The following commands are executed in the shell process however normal command line processing occurs, including input and output redirection (although this is not portable). 

: No effect; the command does nothing.  The exit status is 0. 

. file Read and execute commands from file and return.  The search path $PATH is used to find the directory containing file.

break [n]
Exit from the enclosing for or while loop, if any.  If n is specified, break n levels. 

continue [n]
Resume the next iteration of the enclosing for or while loop.  If n is specified, resume at the n-th enclosing loop.

cd [arg]
Change the current directory to arg. The shell variable HOME defines the default arg. The variable CDPATH defines a search path for the directory arg. It consists of a colon (:) separated list of directories each of which is searched, in turn, for arg. The default CDPATH is the an empty string, which effectively means the current directory. 

echo [arg ...]
The arguments are echoed to standard output.  The command behaves as echo(1v) unless the −b flag is in effect, in which case it behaves as echo(1)). The primary difference is in the interpretation of \ escape sequences (only done if −b is not in effect) and the recognition of a leading −n argument − which only occurs if −b is in effect in the shell. 

eval [arg ...]
The arguments are read as input to the shell and the resulting command(s) executed.

exec [arg ...]
The command specified by the arguments is executed in place of this shell without creating a new process.  Input output arguments may appear and, if no other arguments are given, cause the shell input output to be modified without executing a new process.

exit [n]
Causes a shell to exit with the exit status specified by n. If n is omitted, the exit status is that of the last command executed.  (An end of file will also exit from the shell.) 

export [name ...]
The given names are marked for automatic export to the environment of subsequently-executed commands.  If no arguments are given, a list of exportable names is printed.  Functions cannot be exported, defining a function with the same name as an exported variable will cancel the export of the variable as well as destroying the variable. 

hash [−r] [name]
If -r is given the information about command location is discarded.  If no arguments are given information about all currently remembered commands is printed, else for each name the shell determines and stores the location of the command of that name. 

login [arg ...]
Equivalent to ’exec login arg ...’.

pwd Prints the current directory on the standard output.  See the manual page pwd(1) for more information.

read name ... 
One line is read from the standard input; successive words of the input are assigned to the variables name in order, with leftover words to the last variable.  The return code is 0 unless the end-of-file is encountered. 

readonly [name ...]
The given names are marked readonly, the values of the these names may not be changed by subsequent assignment.  If no arguments are given, a list of all readonly names is printed.

return [n]
Terminates the current function causing the exit status to be n. This command is illegal outside a function definition.  If n is not given the exit status will be that of the last command executed (normally the previous command). 

set [−abefhkntuvx [arg ...]]
The set command allows various aspects of the behaviour of the shell to be controlled. 

−a Automatically export any variable which is created or modified. 

−b Turn on BSD compatibility for the echo command.  See the description of echo above. 

−e If non interactive, exit immediately if a command fails.  This option does not cause the shell to exit if the test in an if or while command fails, although this may happen in other implementations of the shell. 

−f Prevent pattern matching within words.  The processing detailed in the “Filename Generation” subsection is not done. 

−h Locate commands within function definitions when the function is defined.  This does not mean that a subsequent change to the shell PATH variable will not change which commands are executed when a previously defined function is executed.  All the −h flag does is to cause commands in a function definition to be looked up when the function is defined and hence remembered in the command location table (see the hash command above).  When the function is executed the commands will be checked against the location table again and the current location will be used. 

−k All (apparent) shell variable arguments are placed in the environment for a command, not just those that precede the command name.  As a consequence any command argument resembling a shell variable assignment must be quoted. 

−n Read commands but do not execute them.  Notice that this cannot be undone by the “set +n” command as it will not be executed. 

−t Exit after reading and executing one command. 

−u Treat unset variables as an error when substituting. 

−v Print shell input lines as they are read, the output is printed on the error stream. 

−x Print commands and their arguments as they are executed.  The command will be preceded by a “+”.  The command is printed on the error stream. 

If “+” is used in place of “−” the corresponding options are switched off.  If the first argument to set is a single − the x and v options are switched off (this is for backwards compatibility with previous versions of the shell which did not recognise the “+” form of the set command).  If the first argument is −− no flag settings are changed. 

These flags can also be used upon invocation of the shell, in either or both the “−” or “+” form.  The current set of flags may be found in $−. 

Remaining arguments are positional parameters and are assigned, in order, to $1, $2, etc.  If the first argument begins with “−” or “+” and no flags are turned on or off the −− argument should be used.  If no arguments are given, the values of all names are printed. 

shift [n]
The positional parameters from $n+1...  are renamed $1...  n defaults to 1 (renaming $2 to $1 and so on). 

suspend
This command stops the execution of the shell in an environment in which there are job control facilities and is ignored otherwise. The command is equivalent to “kill -TSTP $$”.  If the SIGTSTP signal is ignored by the shell this has no effect, if it is set to the default action (which should only arise if the process which invoked the shell was executing in an environment which supports job control) the shell will stop and control will return to the job control process. 

test The arguments specify various conditions to check.  The exit status of the command is controlled by the result of the tests.  See the manual entry test(1v) for a complete description of the arguments.  Notice that the command syntax is an extension of that supplied by the test command /usr/bin/test described in test(1).

times Print the accumulated user and system times for processes run from the shell. 

trap [arg] [n] ...
Arg is a command to be read and executed when the shell receives signal(s) n. (Note that arg is scanned once when the trap is set and once when the trap is taken.)  Trap commands are executed in order of signal number.  Signals ignored when the shell is started remain ignored − trap commands for these signals will therefore be silently ignored.  The SIGSEGV signal and job control signals which default to stopping a process (see sigvec(2)) cannot be trapped − these signals are SIGTSTP SIGTTIN and SIGTTOU.  If arg is absent but signals are given, all the trap(s) n are reset to their original values.  If arg is the null string, this signal will be ignored by the shell and by invoked commands.  If n is 0, the command arg is executed on exit from the shell, otherwise upon receipt of signal n as numbered in sigvec(2). Trap with no arguments prints a list of commands associated with each signal number.  If a single argument is given and it is −f a list of all traps is given together with the signal name will the initial SIG removed.  If the single argument is −l a list of all allowed signal arguments is given together with their signal name with the initial SIG removed and a short explanation of the signal.  Notice that, although SIGKILL and SIGSTOP are valid for the trap command the kernel will silently ignore requests to trap them.  As an extension to the normal syntax a trap number may be replaced by the signal name with the initial SIG removed − notice that this is not portable. 

type [name ...]
For each command name the shell prints a line indicating where the command is located (including whether it is a shell built-in or a function). 

ulimit [-f] [n]
The −f option is the default and has no effect on the command.  The command limits the size of files created by the shell to n∗512 bytes.  The limit affects the shell and all processes started from it.  Only the super-user can increase the limit.  Without an argument ulimit prints the current size limit. 

umask [nnn]
The user file creation mask is set to the octal value nnn (see umask(2)). If nnn is omitted, the current value of the mask is printed. 

unset [name ...]
Each variable or function named by name is deleted.  If the variable is exported to the environment it will also be removed from the environment of the shell and all processes started from it.  The variables PATH, PS1, PS2, MAILCHECK and IFS cannot be deleted. 

wait [n]
Wait for the specified process and report its termination status.  If n is not given, all currently active child processes are waited for.  The return code from this command is that of the process waited for. 

Invocation

If the first character of argument zero is −, commands are read from /etc/profile then from $HOME/.profile, if such files exist.  Commands are then read as described below.  The shell can be given option arguments starting with “−” or “+” with the same interpretation as the arguments to the set command above.  In addition four extra option letters are recognised.  Notice that the arguments after the option letters are interpreted as the name of a file containing shell commands followed by values for the positional variables (see “Parameter Substitution” above), unless the −c or −s option is given. 

−c string If the −c flag is present, string is interpreted as a sequence of commands to execute.  The remaining arguments are assigned to the positional variables in turn. 

−s If the −s flag is present or if no arguments remain then commands are read from the standard input.  The arguments after the option arguments are assigned in turn to the positional variables.  Output produced by the shell (except for non-error output from positional commands) is written to file descriptor 2. 

−i If the −i flag is present or if the shell input and output are attached to a terminal (as told by isatty(3)) then this shell is interactive.  In this case the terminate signal SIGTERM (see sigvec(2)) is ignored (so that “kill 0” does not kill an interactive shell) and the interrupt signal SIGINT is caught and ignored (so that wait is interruptible).  In all cases SIGQUIT is ignored by the shell. 

−r If the −r flag is present, or the name of the shell is rsh (as found from argument 0) or the SHELL environment variable contains a letter “r” the shell behaves as a restricted shell (see the next subsection). 

The remaining flags and arguments are described under the set command. 

The Restricted Shell

The shell becomes a restricted shell if invoked with the −r flag or if its name is rsh or the file name in the SHELL environment variable contains an “r” character (as described above). 

The restricted shell provides a controlled environment for untrusted users or processes.  Certain built-in commands cannot be executed and external commands must not be specified using absolute path names:

cd This command cannot be executed.  The rsh user is thus forced to remain in their initial directory. 

commands The names of commands to be executed must not contain the “/” character; thus all commands must be in the PATH or in the current directory. 

PATH This shell variable cannot be changed − thus the range of commands available to the rsh user is known. 

IO Input and output redirection is forbidden; thus the user can only write to or create new files using the supplied commands. 

These restrictions come into effect after the system and user .profile files have been executed, thus these can be used to provide appropriate facilities to the user. 

EXIT STATUS

The exit status of the shell is the exit status of the last command executed (ie the status in $?) unless the exit command is used to terminate the shell.  Errors within the input to the shell (for example bad syntax or non-existent commands) cause a failure status to be set:

1 Non-existent command or a similar recoverable error, including errors in built-in commands. 

2 Syntax error (for example a badly formed if command). 

Unless the −e flag is in effect a failure code of “1” causes the shell to output an error message and continue, whereas a failure code of “2” causes the shell to terminate the operation.  If the shell is interactive control will be returned to the user, if it is not interactive the shell will exit with the relevant status code.  The shell will exit on any failure if the −e flag is in effect (an interactive shell will also exit). 

NOTES

The facilities for operation within an environment which supports job control are extremely limited.  Even without job control sh could handle the job control signals, however it is normally the case that these will only arise if the shell is running under the control of another (job control) process, such as csh(1).

FILES

/etc/profile
$HOME/.profile
/tmp/sh∗
/dev/null

SEE ALSO

cd (1), csh(1), echo (1v), echo (1), pwd (1), test(1), umask (1), execve(2), environ(7)

System V  —  Revision 1.6 of 22/10/90

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026