sh(C)


sh -- invoke the shell command interpreter

Syntax

sh [ -aceikLnrstuvx ] [ args ]

Description

The shell is the standard command programming language that executes commands read from a terminal or a file. The shell reads lines and either executes them (if they are an external program), or interprets them as statements in the shell programming language. Each input line is scanned and split into tokens; parameters are substituted (subject to quoting), filenames are generated, input and output are (optionally) redirected, then the commands are executed. See ``Invocation'' for the meaning of arguments to the shell.

NOTE: If you require the functionality supplied by sh as defined by ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992) and X/Open CAE Specification, Commands and Utilities, Issue 4, 1992, refer to ksh(C), which documents /bin/posix/sh.

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 ).exec(S-osr5) The value of a simple-command is its exit status if it terminates normally. If it terminates abnormally, it returns the value of the exit signal number + SIGFLG, where SIGFLG is (octal) 0200. See signal(S-osr5) for a list of signal numbers.

A pipeline is a sequence of one or more commands separated by a vertical bar (|). (The caret (^), is an obsolete synonym for the vertical bar and should not be used in a pipeline. Scripts that use ``^'' for pipelines are incompatible with the Korn shell.) The standard output of each command but the last is connected by a pipe(S-osr5) to the standard input of the next command. Each command is run as a separate process; the shell waits for the last command to terminate.

A list is a sequence of one or more pipelines separated by ;, &, &&, or ||, and optionally terminated by ; or &. Of these four symbols, ; and & have equal precedence, which is lower than that of && and ||. The symbols && and || also have equal precedence. A semicolon (;) causes sequential execution of the preceding pipeline; an ampersand (&) causes asynchronous execution of the preceding pipeline (that is, the shell does not wait for that pipeline to finish). The symbol && causes the list following it to be executed if the preceding pipeline succeeded (returned a 0 exit status). The symbol || causes the list following it to be executed only if the preceding pipeline failed (returned a non-zero exit status). An arbitrary number of newlines may appear in a list, instead of semicolons, to delimit commands.

A command is either a simple-command or one of the following commands. Unless otherwise stated, 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 taken from the in word list. If in word is omitted, then the for command executes the do list once for each positional parameter that is set (see ``Parameter substitution''). 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 filename generation (see regexp(M) for details).

if list
then
list
[ elif list
then
list ]
...
[ else list ]
fi

The list following if is executed and, if it returns a 0 exit status, the list following the first then is executed. Otherwise, the list following elif is executed and, if its value is 0, the list following the next then is executed. Failing that, the else list is executed. If no else list or then list is executed, then the if command returns a 0 exit status. Note that the then keyword must fall on a new line.

while list
do
list
done

A while command repeatedly executes the while list and, if the exit status of the last command in the list is 0, executes the do list; otherwise the loop terminates. If no commands in the do list are executed, then the while command returns a 0 exit status; until may be used in place of while to negate the loop termination test.


until list
do
list
done

until is similar to while, except that until continues execution until the first list returns a 0 exit status. In other words, until works until the test condition succeeds (it works the whole time the command is failing); while works until the test condition fails. until is useful when you are waiting for a particular event to occur.

(list)

This executes list in a subshell.

{list;}

This simply executes list.

name ( ) {list;}

This defines a function which is referenced by name. The body of functions is the list of commands between { and }. Execution of functions is described later (see ``Execution'').

The following words are reserved only when they are the first word of a command and when they are not quoted:

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

Comments

A word beginning with # causes that word and all the following characters up to a newline to be ignored.

Command substitution

The standard output from a command enclosed between grave accents (` `) may be used as part or all of a word; trailing newlines are removed.

No interpretation is done on the command string before the string is read, except to remove backslashes (\) used to escape other characters. Backslashes may be used to escape grave accents (`) or other backslashes and are removed before the command string is read. Escaping grave accents allows nested command substitution. If the command substitution lies within a pair of double quotes (" ` ... ` "), backslashes used to escape a double quote (\") are removed; otherwise, they are left intact.

If a backslash is used to escape a newline character, both the backslash and the newline are removed (see the section on ``Quoting''). In addition, backslashes used to escape dollar signs (\$) are removed. Since no interpretation is done on the command string before it is read, inserting a backslash to escape a dollar sign has no effect. Backslashes that precede characters other than \, `, ", newline, and $ are left intact.

Parameter substitution

The character $ is used to introduce substitutable parameters. There are two types of parameters, positional and keyword. If a parameter is a digit, it is a positional parameter. Positional parameters may be assigned values by set. Keyword parameters, (also known as variables) may be assigned values by writing:

name = value [ name = value ] ...

Pattern-matching is not performed on value. There cannot be a function and a variable with the same name.


${parameter}
A parameter is a sequence of letters, digits, or underscores (a name), a digit, or any of the characters *, @, #, ?, -, $, and !. 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. A name must begin with a letter or underscore. If parameter is a digit then it is a positional parameter. If parameter is * or @, then all the positional parameters, starting with $1, are substituted (separated by spaces). Parameter $0 is set from argument 0 when the shell is invoked.

${parameter:-word}
If parameter is set and is not a null argument, its value is substituted; otherwise word is substituted.

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

${parameter:?word}
If parameter is set and is not a null argument, its value is substituted; otherwise, word is printed and the shell is exited. If word is omitted, the message ``parameter null or not set'' is printed.

${parameter:+word}
If parameter is set and is not a null argument, word is substituted; otherwise nothing is substituted.

In the above, word is not evaluated unless it is to be used as the substituted string, so that in the following example, pwd is executed only if d is not set or is null:

echo ${d:- `pwd` }

If the colon (:) is omitted from the above expressions, then the shell only checks whether parameter is set.

The following parameters are automatically set by the shell:


#
The number of positional parameters in decimal

-
Flags supplied to the shell on invocation or by the set command

?
The decimal value returned by the last synchronously executed command

$
The process number of this shell

!
The process number of the last background command invoked

The following parameters are used by the shell:


CDPATH
The search path for the cd special command. See the section for cd under ``Special commands''.

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

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

MAIL
If this variable is set to the name of a mail file, then the shell informs the user of the arrival of mail in the specified file.

MAILCHECK
This parameter specifies how often (in seconds) the shell checks for the arrival of mail in the files specified by the MAILPATH or MAIL parameters. The default value is 600 seconds (10 minutes). If it is set to 0, the shell checks before each prompt.

MAILPATH
A colon (:) separated list of filenames. If this parameter is set, the shell informs the user of the arrival of mail in any of the specified files. Each filename can be followed by ``%'' and a message to be printed when the modification time changes. The default message is ``you have mail''.

PATH
The search path for commands (see ``Execution'').

PS1
The primary prompt string, by default ``$ ''.

PS2
The secondary prompt string, by default ``> ''.

SHELL
When the shell is invoked, it scans the environment (see ``Environment'') for this name. If it is found and there is an `r' in the filename part of its value, the shell becomes a restricted shell.

The shell gives default values to PATH, PS1, PS2, and IFS, while HOME and MAIL are not set at all by the shell (although HOME is set by login(M)).

Blank interpretation

After parameter and command substitution, the results of substitution are scanned for internal field separator characters (those found in IFS) and split into distinct arguments where such characters are found. Explicit null arguments ("" or '') are retained. Implicit null arguments (those resulting from parameters that have no values) are removed.

Filename generation

Following substitution, each command word is scanned for patterns (shell regular expressions), as described in regexp(M).

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 (that is, made to stand for itself) by preceding it with a ``\''. The pair \newline is ignored. All characters enclosed between a pair of single quotation marks (' '), except a single quotation mark, are quoted. Inside double quotation marks (" "), parameter and command substitution occurs and ``\'' quotes the characters \, `, ", and $. "$*" is equivalent to "$1 $2 ...", whereas "$@" is equivalent to "$1" "$2" ...

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 (that is, the value of PS2) is issued.

Spelling checker

When using cd(C) the shell checks spelling. For example, if you change to a different directory using cd and misspell the directory name, the shell responds with an alternative spelling of an existing directory. Enter ``y'' and press <Return> (or just press <Return>) to change to the offered directory. If the offered spelling is incorrect, enter ``n'', then retype the command line. In this example the user input is boldfaced:

$ cd /usr/spool/uucp

   cd /usr/spool/uucp?y
   ok

Input/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. They are not passed on to the invoked command; substitution occurs 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 to it (by first seeking the end-of-file); otherwise, the file is created.

<<[ - ]word
Read the shell input up to a line that is the same as word, or to an end-of-file. The resulting document becomes 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, (unescaped) \newline is ignored, and ``\'' must be used to quote the characters \, $, `, and the first character of word. If ``-'' is appended to <<, all leading tabs are stripped from word and from the document.

<&digit
Duplicate the standard input from file descriptor digit (see );dup(S-osr5) similarly for the standard output using >.

<&-
Close the standard input; 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

creates file descriptor 2 that is a duplicate of file descriptor 1.

If a command is followed by ``&'', 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.

Environment

The environment (see environ(M)) is a list of name-value pairs that is passed to an executed program in the same way as a normal argument list. 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 affect 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 composed of any unmodified name-value pairs originally inherited by the shell, minus any pairs removed by unset, 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 the following two statements are equivalent (as far as the above execution of cmd is concerned).

   TERM=wy60 cmd args

   (export TERM; TERM=wy60; cmd args)

If the -k flag is set, all keyword arguments are placed in the environment, even if they occur after the command name.

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, with the exception of signal 11. See the trap command.

Execution

Each time a command is executed, the substitutions described in the previous sections are carried out. If the command name does not match a special command, but matches the name of a defined function, the function is executed in the shell process (note how this differs from the execution of shell procedures). The positional parameters $1, $2, ... are set to the arguments of the function. If the command name matches neither a special command nor the name of a defined function, a new process is created and an attempt is made to execute the command via .exec(S-osr5)

The shell parameter PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The default path is :/bin:/usr/bin (specifying the current directory, /bin, and /usr/bin, in that order). Note that the current directory is specified by a null pathname, which can appear immediately after the equal sign or between the colon delimiters anywhere else in the path list. If the command name contains a ``/'', then the search path is not used. Otherwise, each directory in the path is searched for an executable file. If the file has execute permission but is not an a.out file, it is assumed to be a file containing shell commands. A subshell (that is, a separate process) is spawned to read it. A parenthesized command is also executed in a sub-shell.

Shell procedures are often used by users running the csh. However, if the first character of the procedure is a ``#'' (comment character), csh assumes the procedure is a csh script, and invokes /bin/csh to execute it. sh procedures should always be started with some other character if csh users are to run the procedure at any time. This invokes the standard shell /bin/sh.

The location in the search path where a command was found is remembered by the shell (to help avoid unnecessary execs later). If the command was found in a relative directory, its location must be re-determined whenever the current directory changes. The shell forgets all remembered locations whenever the PATH variable is changed or the hash -r command is executed (see hash in the next section).

Special commands

Input/output redirection is permitted for these commands:

:
No effect; the command does nothing. A 0 exit code is returned.

. file
Reads and executes commands from file and returns. The search path specified by PATH is used to find the directory containing file.

break [ n ]
Exits from the enclosing for, while, or until loop, if any. If n is specified, it breaks n levels.

continue [ n ]
Resumes the next iteration of the enclosing for, while, or until loop. If n is specified, it resumes at the nth enclosing loop.

cd [ -L | -P ] [ arg ]
Changes the current directory to arg. The shell parameter HOME is the default arg. The shell parameter CDPATH defines the search path for the directory containing arg. Alternative directory names are separated by a colon (:). The default path is <null> (specifying the current directory). Note that the current directory is specified by a null pathname, which can appear immediately after the equal sign or between the colon delimiters anywhere else in the path list. If arg begins with a ``/'', the search path is not used. Otherwise, each directory in the path is searched for arg.

If the shell is reading its commands from a terminal, and the specified directory does not exist (or some component cannot be searched), spelling correction is applied to each component of arg, in a search for the ``correct'' name. The shell then asks whether or not to try and change directory to the corrected directory name; an answer of n means ``no'', and anything else is taken as ``yes''.

The -L and -P flags are relevant to systems with symbolic links:


-L
Preserve logical pathnames so that cd -L .. moves up one component towards the root along the current logical path.

-P
Use a physical model for pathnames so that cd -L .. moves up one component towards the root by following the link to the parent of the current directory. This is the default behavior.
For example, if /usr/include/sys/h is a symbolic link to the directory /sys/h, then cd /usr/include/sys/h; cd -L .. would make /usr/include/sys the current directory; cd /usr/include/sys/h; cd -P .. would make /sys the current directory.

If the -L option is specified to sh (or to set), the default behavior of cd is to use logical pathnames.


echo [ arg ]
Writes arguments separated by blanks and terminated by a newline on the standard output. Arguments may be enclosed in quotes. Quotes are required so that the shell correctly interprets these special escape sequences:

\b Backspace
\c Prints line without newline
\f Form feed
\n Newline
\r Carriage return
\t Tab
\v Vertical tab
\\ Backslash
\n The 8-bit character whose ASCII code is the 1, 2 or 3-digit
octal number n. n must start with a 0


eval [ arg ... ]
Reads the arguments as input to the shell and executes the resulting command(s).

exec [ arg ... ]
Executes the command specified by the arguments 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.

exit [ n ]
Causes the 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 also causes the shell to exit.

export [ name ... ]
Marks the given names for automatic export to the environment of subsequently executed commands. If no arguments are given, a list of all names that are exported in this shell is printed.

getopts
Is used in shell scripts to support command syntax standards (see Intro(C)); it parses positional parameters and checks for legal options. See getopts(C) for usage and description.

hash [ -r ] [ name ... ]
Determines and remembers, for each name, the location in the search path of the command specified by name. The -r option causes the shell to forget all remembered locations. If no arguments are given, information about remembered commands is presented. ``Hits'' is the number of times a command has been invoked by the shell process. ``Cost'' is a measure of the work required to locate a command in the search path. There are certain situations which require that the stored location of a command be recalculated. Commands for which this is done are indicated by an asterisk (*) adjacent to the ``hits'' information. ``Cost'' is incremented when the recalculation is done.

newgrp [ arg ... ]
Equivalent to exec newgrp arg ...

pwd [ -L | -P ]
Prints the current working directory. The -L and -P flags are useful with symbolic links:

-L
Show the logical pathname to the directory preserving the route taken to get there.

-P
Show the physical pathname to the directory. This is the default behavior.

For example, if /usr/include/sys/h is a symbolic link to the directory /sys/h, then cd /usr/include/sys/h; pwd -L prints /usr/include/sys/h as the current working directory; cd/usr/include/sys/h; pwd -P prints /sys/h as the current working directory.

If the -L option is specified to sh (or to set), the default behavior of pwd is to use logical pathnames.


read [ name ... ]
Reads one line from the standard input and assigns the first word to the first name, the second word to the second name, and so on, with leftover words assigned to the last name. The return code is 0 unless an end-of-file is encountered.

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

return [ n ]
Causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command executed.

set [ -aefhknuvx [ arg ... ] ]
set takes the following options:

-a
Marks variables which are modified or created for export.

-e
If the shell is non-interactive, exits immediately if a command exits with a non-zero exit status.

-f
Disables filename generation.

-h
Locates and remembers function commands as functions are defined (function commands are normally located when the function is executed). For example, if h is set, /bin/tty is added to the hash table when:
showtty(){
	tty
}
is declared. If h is unset, the function is not added to the hash table until showtty is called.

-k
Places all keyword arguments in the environment for a command, not just those that precede the command name.

-L
Causes the internal cd and pwd commands to use logical pathnames by default rather than physical pathnames.

-n
Reads commands but does not execute them.

-u
Treats unset variables as an error when substituting.

-v
Prints shell input lines as they are read.

-x
Prints commands and their arguments as they are executed. Although this flag is passed to sub-shells, it does not enable tracing in those sub-shells.

--
Does not change any of the flags; this is useful in setting $1 to ``-''. Using ``+'' rather than ``-'' causes these flags to be turned off. These flags can also be used upon invocation of the shell. The current set of flags may be found in $-. The remaining arguments are positional parameters and are assigned, in order, to $1, $2, ... If no arguments are given, the values of all names are printed.

shift [n]
Renames the positional parameters from $2 ... to $1 ... If n is specified, it shifts the positional parameters by n places. shift is the only way to access positional parameters above $9.

test
Evaluates conditional expressions. See test(C) for usage and description.

times
Prints 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. The highest signal number allowed is 16. Any attempt to set a trap on a signal that was ignored on entry to the current shell is ineffective. An attempt to trap on signal 11 (memory fault) produces an error. If arg is absent, all trap(s) n are reset to their original values. If arg is the null string, this signal is ignored by the shell and by the commands it invokes. If n is 0, the command arg is executed on exit from the shell. The trap command with no arguments prints a list of commands associated with each signal number.

type [ name ... ]
Indicates, for each name, how it would be interpreted if used as a command name.

ulimit [ -acdfnstvHS ] [ limit ]
Set or display a resource limit. If a limit is provided, then the resource limit is set. The list of available resources is given below. The limit argument should be either a number or the word ``unlimited''. The -H flag sets the hard limit and the -S flag sets the soft limit. If neither -H nor -S is specified, both the hard and soft limits will be set. The hard limit cannot be raised, but the soft limit can be set to any value up to the hard limit.

 
If no limit is provided, the current limit is printed. The soft limit is printed unless the -H flag is specified. If more than one resource limit is printed, a description of each resource is printed before the limit.

 
If no resource is specified when setting or displaying limits, the -f flag is assumed.
The following flags are recognized:

-a
List all the current resource limits.

-c
Size of core files (in 512-byte blocks).

-d
Size of data region (in KB).

-f
Size of files created (in 512-byte blocks).

-n
Number of open file descriptors.

-s
Size of process's stack (in KB).

-t
Number of seconds used by each process.

-v
Size of a process's virtual address space (in KB).
See also ulimit(C).

unset [ name ... ]
Removes, for each name, the corresponding variable or function. The variables PATH, PS1, PS2, MAILCHECK and IFS cannot be unset.

umask [ -S ] [ mask ]
Sets the user file-creation mask to the value of the mask operand. If mask is an octal integer, the specified bits are set in the umask. Otherwise, mask should be symbolic mode (see chmod(C)), the new value of the file-creation mask being the logical complement of the file permission bits specified. If no mask is specified, the current file-creation mask is printed. If -S is specified, the symbolic form is printed. See also umask(C).

wait [ n ]
Waits for the specified process to terminate, and reports the termination status. If n is not given, all currently active child processes are waited for. The return code from this command is always 0.

Invocation

If the shell is invoked through exec(S-osr5) and the first character of argument 0 is ``-'', commands are initially read from /etc/profile and then from $HOME/.profile, if such files exist. Thereafter, commands are read as described below, which is also the case when the shell is invoked as /bin/sh. The flags below are interpreted by the shell on invocation only; note that unless the -c or -s flag is specified, the first argument is assumed to be the name of a file containing commands, and the remaining arguments are passed as positional parameters to that command file:

-c string
If the -c flag is present, commands are read from string.

-s
If the -s flag is present or if no arguments remain, commands are read from the standard input. Any remaining arguments specify the positional parameters. Shell output is written to file descriptor 2.

-t
If the -t flag is present, a single command is read and executed, and the shell exits. This flag is intended for use by C programs only and is not useful interactively.

-i
If the -i flag is present or if the shell input and output are attached to a terminal, this shell is interactive. In this case, TERMINATE is ignored (so that kill 0 does not kill an interactive shell) and INTERRUPT is caught and ignored (so that wait is interruptible). In all cases, QUIT is ignored by the shell.

-r
If the -r flag is present, the shell is a restricted shell (see rsh(C)).
The remaining flags and arguments are described under the set command in ``Special commands''.

Exit values

Errors detected by the shell, such as syntax errors, cause the shell to return a non-zero exit status. If the shell is being used non-interactively, execution of the shell file is abandoned. Otherwise, the shell returns the exit status of the last command executed. See the exit command above.

Examples

See ``Solving problems with the environment'' and Chapter 11, ``Automating frequent tasks'' in the Operating System User's Guide in the SCO OpenServer Operating System User's Guide for a general introduction to shell programming, and the development of an example script.

See See ``Tuning script performance'' in the Operating System User's Guide for a general discussion of shell script efficiency considerations and some examples of generic scripts.

Notes

The command readonly (without arguments) produces the same type of output as the command export.

If << is used to provide standard input to an asynchronous process invoked by &, the shell gets mixed up about naming the input document; a garbage file /tmp/sh* is created and the shell complains about not being able to find that file by another name.

If a command is executed, and a command with the same name is installed in a directory in the search path before the directory where the original command was found, the shell continues to exec the original command. Use the hash command to correct this situation.

If you move the current directory or one above it, pwd may not give the correct response. Use the cd command with a full pathname to correct this situation.

When a sh user logs in, the system reads and executes commands in /etc/profile before executing commands in the user's $HOME/.profile. You can, therefore, modify the environment for all sh users on the system by editing /etc/profile.

The shell doesn't treat the high (eighth) bit in the characters of a command line argument specially, nor does it strip the eighth bit from the characters of error messages. Previous versions of the shell used the eighth bit as a quoting mechanism.

Existing programs that set the eighth bit of characters in order to quote them as part of the shell command line should be changed to use of the standard shell quoting mechanisms (see the section on ``Quoting'').

Words used to specify filenames in input/output redirection are not expanded for filename generation (see the section on ``Filename generation''). For example, cat file1 > a* creates a file named a*.

Because commands in pipelines are run as separate processes, variables set in a pipeline have no effect on the parent shell.

If you get the error message:

   fork failed - too many processes
try using the wait(C) command to clean up your background processes. If this does not help, the system process table is probably full or you have too many active foreground processes (there is a limit to the number of processes that can be associated with your login, and the number the system can keep track of).

Warning

Not all processes of a 3 or more stage pipeline are children of the shell, and thus cannot be waited for.

For wait n, if n is not an active process ID, all your shell's currently active background processes are waited for and the return code is 0.

Files


/etc/profile
system default profile, read by login shells

$HOME/.profile
read by login shell at login

/tmp/sh*
temporary file for <<

/dev/null
source of empty file

Open UNIX 8 compatibility notes

When running ACP on Open UNIX 8 and UnixWare 7 systems, set OSRCMDS=on to use the SCO OpenServer version of the <sh> command. This provides the expected behaviors for SCO OpenServer applications. The SCO OpenServer version of this command is also provided on Open UNIX 8 systems under the OSP feature See the Running SCO OpenServer Applications topic in the Open UNIX 8 documentation set.

See also

a.out(FP), cd(C), dup(S-osr5), env(C), environ(M), exec(S-osr5), fork(S-osr5), ksh(C), login(M), newgrp(C), pipe(S-osr5), profile(M), regexp(M), rsh(C), signal(S-osr5), test(C), umask(C), umask(S-osr5), wait(S-osr5)

Chapter 10, ``Configuring and working with the shells'' in the SCO OpenServer Operating System User's Guide

Standards conformance

sh is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005