Content-type: text/html Man page of sh

sh

Section: Misc. Reference Manual Pages (1p)
Index Return to Main Contents
 

NAME

sh - Shell, the standard command language interpreter (POSIX Shell)  

SYNOPSIS

sh [-ir] [-c command_string|-s] [+|-abCefhkmnopstuvx] [+|-o][option...]|[+|-A name] [argument...]|[file] [argument...]

The POSIX shell is an interactive command interpreter and a command programming language.
 

STANDARDS

Interfaces documented on this reference page conform to industry standards as follows:

sh:  XPG4, XPG4-UNIX

Refer to the standards(5) reference page for more information about industry standards and associated tags.
 

OPTIONS

Causes sh to read commands from command_string. Causes sh to run as an interactive shell. The SIGTERM signal is thus ignored, and the SIGINT signal is caught, causing the current command to be terminated and a new prompt to be output. [Compaq]  Causes sh to run as a restricted shell. Causes sh to read commands from standard input. If you do not specify the -c option or do not specify any arguments to sh other than options, sh automatically invokes the -s option. The -c option overrides the -s option.

[Compaq]  The rest of the options that can be used with sh are described under the set subcommand in the subsection Special sh Commands.
 

DESCRIPTION

The POSIX shell carries out commands either interactively from a terminal keyboard or from a file.

Some important features of the shell are as follows: Command aliasing File name substitution Tilde substitution Command substitution Parameter substitution Job control Inline editing

A file from which the shell carries out commands is usually called a shell script, a shell procedure, or a command file.

A simple command is a sequence of words separated by spaces or tabs. A word is a sequence of characters that contains no unquoted spaces or tabs. The first word in the sequence (numbered as 0), usually specifies the name of a command. Any remaining words, with a few exceptions, are passed to that command. A space refers to both spaces and tabs.

[Compaq]  The value of a simple command is its exit value if it ends normally, or (octal) 200 added to the signal number if it terminates due to a signal. For a list of status values, see the signal(2) reference page.

A pipeline is a sequence of one or more commands separated by a | (vertical bar) or, for historical compatibility, by a ^ (circumflex). In a pipeline, the standard output of each command becomes the standard input of the next command. Each command runs as a separate process, and the shell waits for the last command to end. A filter is a command that reads its standard input, transforms it in some way, then writes it to its standard output. A pipeline normally consists of a series of filters. Although the processes in a pipeline (except the first process) can execute in parallel, they are synchronized to the extent that each program needs to read the output of its predecessor.

The exit value of a pipeline is the exit value of the last command.

A list is a sequence of one or more pipelines separated by ; (semicolon), & (ampersand), && (two ampersands), or || (two vertical bars) and optionally ended by a ; (semicolon), an & (ampersand), a |& (coprocess), or a newline. These separators and terminators have the following effects: Causes sequential execution of the preceding pipeline; the shell waits for the pipeline to finish. Causes asynchronous execution of the preceding pipeline; the shell does not wait for the pipeline to finish. Causes the list following it to be executed only if the preceding pipeline returns a 0 (zero) exit value. Causes the list following it to be executed only if the preceding pipeline returns a nonzero exit value.

[Compaq]  The cd command is an exception; if it returns a nonzero exit value, no subsequent commands in a list are executed, regardless of the separator characters.

The ; and & separators have equal precedence, as do && and ||. The single-character separators have lower precedence than the double-character separators. An unquoted newline character following a pipeline functions the same as a ; (semicolon).
 

Comments

The shell treats as a comment any word that begins with a # character and ignores that word and all characters following up to the next newline character.
 

Shell Flow Control Statements

Unless otherwise stated, the value returned by a command is that of the last simple command executed in the command. Each time a for command is executed, identifier is set to the next word taken from the in word list. If in word ... is omitted, 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. Prints on standard error (file descriptor 2), the set of words, each preceded by a number. If in word... is omitted, then the positional parameters are used instead. (See Parameter Substitution.) The PS3 prompt is printed and a line is read from the standard input. If this line consists of the number of one of the listed words, then the value of the parameter identifier is set to the word corresponding to this number. If this line is empty, the selection list is printed again. Otherwise, the value of the parameter identifier is set to null. The contents of the line read from standard input is saved in the REPLY parameter. The list is executed for each selection until a break or End-of-File is encountered. 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. (See File name Generation.) Executes the list following if and, if it returns a 0 (zero) exit status, executes the list following the first then. Otherwise, the list following elif is executed and, if its value is 0 (zero), 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 (zero) exit status. Executes the while list repeatedly, and if the exit status of the last command in the list is 0 (zero), executes the do list; otherwise the loop terminates. If no commands in the do list are executed, then the while command returns a 0 (zero) exit status; until can be used in place of while to negate the loop termination test. Executes list in a separate environment. If two adjacent open parentheses are needed for nesting, a space must be inserted to avoid arithmetic evaluation as described later. Executes list. Unlike the metacharacters ( and ), { and } are reserved words and must be at the beginning of a line or after a ; (semicolon) in order to be recognized. Evaluates expression and returns a 0 (zero) exit status when expression is TRUE. See Conditional Expressions for a description of expression. Defines a function that is referenced by identifier. The body of the function is the list of commands between { and }. (See Functions.) Executes pipeline and prints the elapsed time as well as the user and system time on standard error.

The following reserved words are recognized only when they appear, without single or double quotes, as the first word of a command:

if for case then while esac else until function elif do select fi done time { } [[ ]]


 

Command Aliasing

The first word of each command is replaced by the text of an alias (if an alias for this word was defined). The first character of an alias name can be any nonspecial printable character, but the rest of the characters must be the same as for a valid identifier. The replacement string can contain any valid shell script, including the metacharacters previously listed. The first word of each command in the replaced text, other than any that are in the process of being replaced, is tested for aliases. If the last character of the alias value is a space, the word following the alias will also be checked for alias substitution.

Aliases can be used to redefine special built-in commands but cannot be used to redefine the reserved words previously listed. Aliases can be created, listed, and exported with the alias command and can be removed with the unalias command. Exported aliases remain in effect for scripts invoked by name, but must be reinitialized for separate invocations of the shell. (See Invocation.)

Aliasing is performed when scripts are read, not while they are executed. Therefore, for an alias to take effect, the alias definition command has to be executed before the command that references the alias is read.

Aliases are frequently used as shorthand for full pathnames. An option to the aliasing facility allows the value of the alias to be automatically set to the full pathname of the corresponding command. These aliases are called tracked aliases.

[Compaq]  The value of a tracked alias is defined the first time the corresponding command is looked up and becomes undefined each time the PATH environment variable is reset. These aliases remain tracked so that the next subsequent reference will redefine the value. Several tracked aliases are compiled into the shell. The -h option of the set command makes each referenced command name into a tracked alias.

[Compaq]  The following exported aliases are compiled into the shell, but can be unset or redefined:

autoload='typeset -fu' false='let 0' functions='typeset -f' hash='alias -t' history='fc -l' integer='typeset -i' nohup='nohup ' r='fc -e -' true=':' type='whence -v'


 

Tilde Substitution

After alias substitution is performed, each word is checked to see if it begins with an unquoted ~ (tilde). If it does, then the word up to a / (slash) is checked to see if it matches a username in the /etc/passwd file. If a match is found, the tilde and the matched login name are replaced by the login directory of the matched user. This is called a tilde substitution. If no match is found, the original text is left unchanged. A tilde by itself, or in front of a /, is replaced by the value of the HOME parameter. A tilde followed by a + (plus sign) or - (dash) is replaced by $PWD and $OLDPWD, respectively.

In addition, tilde substitution is attempted when the value of a variable assignment parameter begins with a tilde.
 

Command Substitution

The standard output from a command enclosed in parentheses preceded by a dollar sign $( ) or a pair of `` (grave accents) can be used as part or all of a word; trailing newlines are removed. In the second (archaic) form, the string between the grave accents is processed for special quoting characters before the command is executed. (See Quoting.) The command substitution $(cat file) can be replaced by the equivalent but faster $(<file). Command substitution of most special commands that do not perform input/output redirection are carried out without creating a separate process. An arithmetic expression enclosed in double parentheses preceded by a dollar sign ( $(( )) ) is replaced by the value of the arithmetic expression within the double parentheses.
 

Parameter Substitution

A parameter is an identifier, one or more digits, or any of the characters *, @, #, ?, -, $, and !. A named parameter (a parameter denoted by an identifier) has a value and 0 (zero) or more attributes. Named parameters can be assigned values and attributes by using the typeset special command. The attributes supported by the shell are described later with the typeset special command. Exported parameters pass values and attributes to the environment.

The shell supports a 1-dimensional array facility. An element of an array parameter is referenced by a subscript. A subscript is denoted by an arithmetic expression enclosed with [ ] (brackets). To assign values to an array, use set -A name value ... The value of all subscripts must be in the range of 0 to 1023. Arrays need not be declared. Any reference to a named parameter with a valid subscript is legal and an array is created if necessary. Referencing an array without a subscript is equivalent to referencing the element 0 (zero).

The value of a named parameter can be assigned by the following:

name=value [ name=value ]

If the integer attribute, -i, is set for name, the value is subject to arithmetic evaluation, as described later. Positional parameters, which are denoted by a number, can be assigned values with the set special command. Parameter $0 is set from argument 0 (zero) when the shell is invoked. The $ (dollar sign) character is used to introduce substitutable parameters. Reads all the characters from the ${ (dollar sign left brace) to the matching } (right brace) as part of the same word even if it contains braces or metacharacters. The value, if any, of the parameter is substituted. The braces are required when parameter is followed by a letter, digit, or underscore that is not to be interpreted as part of its name or when a named parameter is subscripted. If parameter is one or more digits, it is a positional parameter. A positional parameter of more than one digit must be enclosed in braces. If parameter is * (asterisk) or @ (at sign), all the positional parameters, starting with $1, are substituted (separated by a field separator character). If an array identifier with subscript * or @ is used, the value for each of the elements is substituted (separated by a field separator character). Substitutes the number of positional parameters if parameter is * or @; otherwise, the length of the value of the parameter is substituted. Substitutes the number of elements in the array identifier. Substitutes the value of parameter if it is set and non-null; otherwise, substitute word. Sets parameter to word if it is not set or is null; the value of the parameter is then substituted. Positional parameters cannot be assigned values in this way. Substitutes the value of parameter if it is set and is non-null; otherwise, print word and exit from the shell. If word is omitted, a standard message is printed. Substitute word if parameter is set and is non-null; otherwise, substitute nothing. Causes the value of this substitution to be the value of parameter with the matched portion deleted if the shell pattern matches the beginning of the value of parameter; otherwise the value of parameter is substituted. In the first form, the smallest matching pattern is deleted and in the second form, the largest matching pattern is deleted. Causes the value of this substitution to be the value of parameter with the matched part deleted if the shell pattern matches the end of the value of parameter; otherwise, substitute the value of parameter. In the first form, the smallest matching pattern is deleted and in the second form, the largest matching pattern is deleted.

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

In the previous expressions, 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)}

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 executed command. The process number of this shell. [Compaq]  Initially, the value of _ (underscore) is an absolute pathname of the shell or script being executed as passed in the environment. Subsequently, it is assigned the last argument of the previous command. This parameter is not set for commands that are asynchronous. This parameter is also used to hold the name of the matching MAIL file when checking for mail. The process number of the last background command invoked. [Compaq]  The value of errno as set by the most recently failed system call. This value is system dependent and is intended for debugging purposes. The line number of the current line within the script or function being executed. The previous working directory set by the cd command. The value of the last option argument processed by the getopts special command. The index of the last option argument processed by the getopts special command. The process number of the parent of the shell. The present working directory set by the cd command. [Compaq]  Each time this parameter is referenced, a random integer, uniformly distributed between 0 and 32767, is generated. The sequence of random numbers can be initialized by assigning a numeric value to RANDOM. [Compaq]  This parameter is set by the select statement and by the read special command when no arguments are supplied. [Compaq]  Each time this parameter is referenced, the number of seconds since shell invocation is returned. If this parameter is assigned a value, then the value returned upon reference is the value that was assigned plus the number of seconds since the assignment.

The following parameters are used by the shell: The search path for the cd command. If this variable is set, the value is used to define the width of the edit window for the shell edit modes and for printing select lists. If the value of this variable ends in emacs, gmacs, or vi and the VISUAL variable is not set, then the corresponding option (see set under Special sh Commands) is turned on. If this parameter is set, then parameter substitution is performed on the value to generate the pathname of the script that is executed when the shell is invoked. (See Invocation.) This file is typically used for alias and function definitions. The default editor name for the fc command. [Compaq]  The search path for function definitions. This path is searched when a function with the -u attribute is referenced and when a command is not found. If an executable file is found, then it is read and executed in the current environment. Internal field separators, normally spaces, tabs, and newlines that are used to separate command words which result from command or parameter substitution and for separating words with the read special command. The first character of the IFS parameter is used to separate arguments for the $* substitution. (See Quoting.) If this parameter is set when the shell is invoked, then the value is the pathname of the file that is used to store the command history. (See Command Reentry.) If this parameter is set when the shell is invoked, the number of previously entered commands that are accessible by this shell is greater than or equal to this number. The default is 128. The default argument (home directory) for the cd command. Specifies the locale of your system, which is comprised of three parts: language, territory, and codeset. The default locale is the C locale, which specifies the value English for language, U.S. for territory, and ASCII for codeset. The locale specified for the LANG variable controls the language applied to messages. Unless set explicitly, the LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME variables also derive their settings from the locale set for LANG. Specifies the collating sequence to use when sorting names and when character ranges occur in patterns. The default value is the collating sequence for American English. If absent, the collating sequence can be taken from the LANG parameter. If both LC_COLLATE and LANG are absent, the ANSI C collating sequence is used. Specifies the character classification information to use on your system. The default value is American English. Specifies the language that the system expects for user input of yes and no strings. The default value is American English. Specifies the monetary format for your system. The default value is the monetary format for American English. Specifies the numeric format for your system. The default value is the numeric format for American English. Specifies the date and time format for your system. The default value is the date and time format for American English. [Compaq]  If this variable is set, the value is used to determine the column length for printing select lists. Select lists will print vertically until about two-thirds of LINES lines are filled. [Compaq]  The name of the user's login account corresponding to the login name in the user database. If this parameter is set to the name of a mail file and the MAILPATH parameter is not set, the shell informs you of the arrival of mail in the specified file. This variable specifies how often (in seconds) the shell checks for changes in the modification time of any of the files specified by the MAILPATH or MAIL parameters. The default value is 600 seconds. When the time has elapsed, the shell checks before issuing the next prompt. A list of file names separated by : (colons). If this parameter is set, the shell informs you of any modifications to the specified files that have occurred within the last MAILCHECK seconds. Each file name can be followed by a ? (question mark) and a message that is printed. The message will undergo parameter substitution with the parameter, $_ defined as the name of the file that has changed. The default message is you have mail in $_. Specifies a list of directories to search to find message catalogs. The search path for commands. (See Execution.) The value of this parameter is expanded for parameter substitution to define the primary prompt string which by default is the $ (dollar sign). The ! (exclamation point) in the primary prompt string is replaced by the command number. (See Command Reentry.) Secondary prompt string, by default > (right angle bracket). Selection prompt string used within a select loop, by default #? (number sign, question mark). The value of this parameter is expanded for parameter substitution and precedes each line of an execution trace. If omitted, the execution trace prompt is + (plus sign). [Compaq]  The pathname of the shell is kept in the environment. [Compaq]  If set to a value greater than 0 (zero), the shell terminates if a command is not entered within the prescribed number of seconds after issuing the PS1 prompt. (Note that the shell can be compiled with a maximum bound for this value that cannot be exceeded.) If the value of this variable ends in emacs, gmacs, or vi, the corresponding option (see the set command in Special sh Commands) is turned on.

[Compaq]  The shell gives default values to PATH, PS1, PS2, MAILCHECK, TMOUT, and IFS, while HOME, SHELL, ENV, and MAIL are not set by the shell (although HOME is set by the login command). On some systems, MAIL and SHELL are also set by the login command.
 

Interpretation of Spaces

After parameter and command substitution, the results of substitutions are scanned for the 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.
 

File name Generation

Following substitution, each command word is scanned for the characters * (asterisk), ? (question mark), and [ ] (brackets), unless the -f option was set. If one of these characters appears, the word is regarded as a pattern. The word is replaced with lexicographically sorted file names that match the pattern. If no file name is found that matches the pattern, the word is left unchanged. When a pattern is used for file name generation, the . (dot) character at the start of a file name or immediately following a / (slash), as well as the / character itself, must be matched explicitly. In other instances of pattern matching, the / and . are not treated specially. Matches any string, including the null string. Matches any single character. Matches any one of the enclosed characters. In an expression such as [a-z], the - (dash) means ``through'' according to the current collating sequence. The collating sequence is determined by the value of the LC_COLLATE environment variable. If the first character following the [ (left bracket) is a ! (exclamation point), then any character not enclosed is matched. A - can be included in the character set by putting it as the first or last character.

A pattern_list is a list of one or more patterns separated from each other with a | (vertical bar). Composite patterns can be formed with one or more of the following: Optionally matches any one of the given patterns. Matches zero or more occurrences of the given patterns. Matches one or more occurrences of the given patterns. Matches exactly one of the given patterns. Matches anything, except one of the given patterns.
 

Character Classes

You can use the following notation to match file names within a range indication:

[:charclass:]

This format instructs the system to match any single character belonging to charclass; the defined classes correspond to ctype() subroutines as follows:

alnum alpha cntrl digit graph lower print punct space upper xdigit

Your locale might define additional character properties, such as the following:

[:vowel:]

The preceding character class could be TRUE for a, e, i, o, u, or y. You could then use [:vowel] inside a set construction to match any vowel. Refer to The LC_CTYPE Category section of the locale file format reference page for more information.
 

Quoting

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

; & ( ) | ^ < > <newline> <space> <tab>

Each of the metacharacters previously listed has a special meaning to the shell and causes termination of a word unless quoted. A character can be quoted (that is, made to stand for itself) by preceding it with a \ (backslash). The pair \newline is ignored. All characters enclosed between a pair of '' (single quotes) are quoted. A single quote cannot appear within single quotes.

Inside "" (double quotes) parameter and command substitution occurs and \ quotes the characters \, `, ', and $. The meaning of $* and $@ is identical when not quoted or when used as a parameter assignment value or as a file name. However, when used as a command argument, '$*' is equivalent to '$1d$2d. . .', where d is the first character of the IFS parameter, whereas '$@' is equivalent to '$1' '$2' . . . Inside `` (grave accents) \ (backslash) quotes the characters \, `, and $. If the grave accents occur within double quotes, then \ also quotes the ' (single quote) character.

The special meaning of reserved words or aliases can be removed by quoting any character of the reserved word. The recognition of function names or special command names listed later cannot be altered by quoting them.
 

Arithmetic Evaluation

[Compaq]  An ability to perform integer arithmetic is provided with the let special command. Evaluations are performed using long arithmetic. Constants are of the form [base#]n, where base is a decimal number between 2 and 36 representing the arithmetic base and n is a number in that base. If base is omitted, then base 10 is used.

[Compaq]  An arithmetic expression uses the same syntax, precedence, and associativity of expression as the C language. All the integral operators, other than ++, --, ?:, and , are supported. Named parameters can be referenced by name within an arithmetic expression without using the parameter substitution syntax. When a named parameter is referenced, its value is evaluated as an arithmetic expression.

An internal integer representation of a named parameter can be specified with the -i option of the typeset special command. Arithmetic evaluation is performed on the value of each assignment to a named parameter with the -i attribute. If you do not specify an arithmetic base, the first assignment to the parameter determines the arithmetic base. This base is used when parameter substitution occurs.

Because many of the arithmetic operators require quoting, an alternative form of the let command is provided. For any command that begins with a ((, all the characters until a matching )) are treated as a quoted expression. More precisely, ((...)) is equivalent to let "...".

Note that ((...)) is a command with a return value, whereas $((...)) is the way to put the string representation of the value of an arithmetic expression into the command line (that is, it is like a $ variable).
 

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

Conditional Expressions

A conditional expression is used with the [[ compound command to test attributes of files and to compare strings. Word splitting and file name generation are not performed on the words between [[ and ]]. Each expression can be constructed from one or more of the following unary or binary expressions: [Compaq]  TRUE, if file exists. [Compaq]  TRUE, if file exists and is a block-special file. [Compaq]  TRUE, if file exists and is a character-special file. [Compaq]  TRUE, if file exists and is a directory. [Compaq]  TRUE, if file exists. [Compaq]  TRUE, if file exists and is an ordinary file. [Compaq]  TRUE, if file exists and has its setgid bit set. [Compaq]  TRUE, if file exists and its group matches the effective group ID of this process. [Compaq]  TRUE, if file exists and has its sticky bit set. [Compaq]  TRUE, if file exists and is a symbolic link. [Compaq]  TRUE, if length of string is nonzero. [Compaq]  TRUE, if option named option is on. [Compaq]  TRUE, if file exists and is owned by the effective user ID of this process. [Compaq]  TRUE, if file exists and is a FIFO special file or a pipe. [Compaq]  TRUE, if file exists and is readable by current process. [Compaq]  TRUE, if file exists and has size greater than 0 (zero). [Compaq]  TRUE, if file exists and is a socket. [Compaq]  TRUE, if file descriptor number file_des is open and associated with a terminal device. [Compaq]  TRUE, if file exists and has its setuid bit set. [Compaq]  TRUE, if file exists and is writable by current process. [Compaq]  TRUE, if file exists and is executable by current process. If file exists and is a directory, then the current process has permission to search in the directory. [Compaq]  TRUE, if length of string is 0 (zero). [Compaq]  TRUE, if file1 exists and is newer than file2. [Compaq]  TRUE, if file1 exists and is older than file2. [Compaq]  TRUE, if file1 and file2 exist and refer to the same file. [Compaq]  TRUE, if string matches pattern. [Compaq]  TRUE, if string does not match pattern. [Compaq]  TRUE, if string1 collates before string2. [Compaq]  TRUE, if string1 collates after string2. [Compaq]  TRUE, if expression1 is equal to expression2. [Compaq]  TRUE, if expression1 is not equal to expression2. [Compaq]  TRUE, if expression1 is less than expression2. [Compaq]  TRUE, if expression1 is greater than expression2. [Compaq]  TRUE, if expression1 is less than or equal to expression2. [Compaq]  TRUE, if expression1 is greater than or equal to expression2.

[Compaq]  A compound expression can be constructed from these primitives by using any of the following, listed in decreasing order of precedence. [Compaq]  TRUE, if expression is TRUE. Used to group expressions. [Compaq]  TRUE if expression is FALSE. [Digital]  TRUE, if expression1 and expression2 are both TRUE. [Compaq]  TRUE, if either expression1 or expression2 is TRUE.
 

Input/Output

Before a command is executed, you can redirect its input and output by using a special notation interpreted by the shell. The following can appear anywhere in a simple command or can precede or follow a command and are not passed on to the invoked command. Command and parameter substitution occurs before word or digit is used, except as noted in the following text. File name generation occurs only if the pattern matches a single file and interpretation of spaces is not performed. Use file word as standard input (file descriptor 0). Use file word as standard output (file descriptor 1). If the file does not exist, it is created. If the file exists, and the noclobber option is on, this causes an error; otherwise, it is truncated to 0 (zero) length. Same as >, except that it overrides the noclobber option. Use file word as standard output. If the file exists, output is appended to it (by first seeking to the End-of-File); otherwise, the file is created. Open file word for reading and writing as standard input. The shell input is read up to a line that is the same as word, or to an End-of-File. No parameter substitution, command substitution, or file name generation is performed on word. The resulting document, called a here document, becomes the standard input. If any character of word is quoted, then no interpretation is placed upon the characters of the document; otherwise, parameter and command substitution occurs, \newline is ignored, and \ must be used to quote the characters \, $, `, and the first character of word. If - is appended to <<, then all leading tabs are stripped from word and from the document. The standard input is duplicated from file descriptor digit (see the dup(2) reference page). The standard output is duplicated using >& digit. The standard input is closed. The standard output is closed using >&-. The input from the coprocess (or background process) is moved to standard input. The output to the coprocess is moved to standard output.

If one of the preceding redirections is preceded by a digit, then the file descriptor number referred to is that specified by the digit (instead of the default 0 or 1). For example:

... 2>&1

means file descriptor 2 is to be opened for writing as a duplicate of file descriptor 1.

The order in which redirections are specified is significant. The shell evaluates each redirection in terms of the (file descriptor, file) association at the time of evaluation. For example:

... 1>fname 2>&1

first associates file descriptor 1 with file fname. It then associates file descriptor 2 with the file associated with file descriptor 1 (that is, fname). If the order of redirections were reversed, file descriptor 2 is associated with the terminal (assuming file descriptor 1 is) and then file descriptor 1 is associated with file fname.

If a command is followed by & and job control is not active, the default standard input for the command is the empty /dev/null file. 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 is a list of name-value pairs that is passed to an executed program in the same way as a normal argument list. The names must be identifiers and the values are character strings. 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 and marking it export. Executed commands inherit the environment. If you modify the values of these parameters or create new ones, using the export or typeset -x commands, they become part of the environment. The environment seen by any executed command is thus composed of any name-value pairs originally inherited by the shell, whose values can be modified by the current shell, plus any additions that must be noted in the export or typeset -x commands.

[Compaq]  When the value of an exported parameter is changed, the shell automatically exports the new value to all child processes. This behavior is different from that of the Bourne shell, sh(1b), which does not automatically reexport a changed parameter.

You can augment the environment for any simple command or function by prefixing it with one or more parameter assignments. A parameter assignment argument is a word of the form identifier=value.

Thus, the following two expressions are equivalent (as far as the execution of command is concerned):

TERM=450 command argument ...

(export TERM; TERM=450; command argument ...)

[Compaq]  If the -k option is set, all parameter assignment arguments are placed in the environment, even if they occur after the command name. The following first prints a=b c and then c: echo a=b c set -k echo a=b c

[Compaq]  This feature is intended for use with scripts written for early versions of the shell; its use in new scripts is strongly discouraged. It is likely to disappear someday.
 

Functions

The function reserved word is used to define shell functions. Shell functions are read in and stored internally. Alias names are resolved when the function is read. Functions are executed like commands with the arguments passed as positional parameters. (See Execution.)

Functions execute in the same process as the caller and share all files and the present working directory with the caller. Traps caught by the caller are reset to their default action inside the function. A trap condition that is not caught or ignored by the function causes the function to terminate and the condition to be passed on to the caller. A trap on EXIT set inside a function is executed after the function completes in the environment of the caller. Ordinarily, variables are shared between the calling program and the function. However, the special command typeset used within a function defines local variables whose scope includes the current function and all functions it calls.

The special command return is used to return from function calls. Errors within functions return control to the caller.

Function identifiers can be listed with the -f or +f option of the typeset special command. The text of functions is also listed with -f. Function can be undefined with the -f option of the unset special command.

Ordinarily, functions are unset when the shell executes a shell script. The -xf option of the typeset command allows a function to be exported to scripts that are executed without a separate invocation of the shell. Functions that need to be defined across separate invocations of the shell should be specified in the ENV file with the -xf option of typeset.
 

Jobs

If the monitor option of the set command is turned on, an interactive shell associates a job with each pipeline. It keeps a table of current jobs, printed by the jobs command, and assigns them small integer numbers. When a job is started asynchronously with &, the shell prints a line that looks like: [1] 1234

This line indicates that the job, which was started asynchronously, was job number 1 and had one (top-level) process, whose process ID was 1234.

If you are running a job and want to do something else, you can enter the Suspend key sequence (normally <Ctrl-z>, which sends a SIGINT signal to the current job. The shell then normally indicates that the job has been stopped, and it prints another prompt. You can then manipulate the state of this job, putting it in the background with the bg command, or run some other commands and then eventually bring the job back into the foreground with the foreground command fg. The job suspension takes effect immediately, and corresponds to the Interrupt key sequence in that pending output and unread input are discarded. A special key sequence, <Ctrl-y>, does not generate a SIGINT signal until a program attempts to read it. (See the read(2) reference page for more information.) This key sequence can be typed ahead when you have prepared some commands for a job that you wish to stop after it has read them.

A job being run in the background will stop if it tries to read from the terminal. Background jobs are normally allowed to produce output, but this can be disabled by issuing the stty tostop command. If you set this terminal option, then background jobs will stop when they try to produce output like they do when they try to read input.

There are several ways to refer to jobs in the shell. A job can be referred to by the process ID of any process of the job, or by one of the following: The job with the given number. Any job whose command line begins with string. Any job whose command line contains string. Current job. Equivalent to %%. Previous job.

This shell learns immediately whenever a process changes state. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only just before it prints a prompt. This is done so that it does not otherwise disturb your work.

When the monitor mode is on, each background job that is completed triggers any trap set for CHLD.

When you try to leave the shell while jobs are stopped or running, you are warned that You have stopped(running) jobs. You can use the jobs command to see what they are. If you do this or immediately try to exit again, the shell does not warn you a second time, and the stopped jobs are terminated.
 

Signals

The SIGINT and SIGQUIT signals for an invoked command are ignored if the command is followed by & and job monitor option is not active. Otherwise, signals have the values inherited by the shell from its parent (but see also the trap command).
 

Execution

Each time a command is executed, the previous substitutions are carried out. If the command name matches one of the special commands listed later, it is executed within the current shell process. Next, the command name is checked to see if it matches one of the user-defined functions. If it does, the positional parameters are saved and then reset to the arguments of the function call. When the function is completed or issues a return, the positional parameter list is restored and any trap set on EXIT within the function is executed. The value of a function is the value of the last command executed. A function is also executed in the current shell process. If a command name is not a special command or a user-defined function, a process is created and an attempt is made to execute the command via exec.

The PATH shell parameter defines the search path for the directory containing the command. Alternative directory names are separated by a : (colon). The default path is :/usr/bin: (specifying /usr/bin, and the current directory in that order). The current directory can be specified by two or more adjacent colons, or by a colon at the beginning or end of the path list. If the command name contains a / (slash), 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 a directory or an a.out file, it is assumed to be a file containing shell commands. A subshell is spawned to read it. All nonexported aliases, functions, and named parameters are removed in this case. If the shell command file does not have read permission, or if the setuid and/or setgid bits are set on the file, the shell executes an agent whose job it is to set up the permissions and execute the shell with the shell command file passed down as an open file. A command in parentheses is executed in a subshell without removing nonexported quantities.
 

Command Reentry

The text of the last HISTSIZE (default 128) commands entered from a terminal device is saved in a history file. The $HOME/.sh_history file is used if the HISTFILE variable is not set or is not writable. A shell can access the commands of all interactive shells that use the same named HISTFILE. The fc special command is used to list or edit a portion of this file. The portion of the file to be edited or listed can be selected by number or by giving the first character or characters of the command. A single command or range of commands can be specified. If you do not specify an editor program as an argument to fc, then the value of the FCEDIT parameter is used. If FCEDIT is not defined, then /usr/bin/ed is used. The edited commands are printed and reexecuted upon leaving the editor. The editor name - (dash) is used to skip the editing phase and to reexecute the command. In this case, a substitution parameter of the form old=new can be used to modify the command before execution. For example, if r is aliased to 'fc -e -', then typing `r bad=good c' reexecutes the most recent command, which starts with the letter c, replacing the first occurrence of the string bad with the string good.
 

Inline Editing Options

Normally, each command line entered from a terminal device is simply typed followed by a newline (<Return> or linefeed). If the emacs, gmacs, or vi option is active, you can edit the command line. To be in any of these edit modes, set the corresponding option. An editing option is automatically selected each time the VISUAL or EDITOR variable is assigned a value ending in either of these option names.

[Compaq]  The editing features require that the terminal accept <Return> as carriage-return without linefeed and that a space must overwrite the current character on the screen. ADM terminal users should set the space-advance switch to Space. Hewlett-Packard series 2621 terminal users should set the straps to bcGHxZ etX.

[Compaq]  The editing modes create the impression that the user is looking through a window at the current line. The window width is the value of COLUMNS if it is defined, otherwise it is 80 bytes. If the line is longer than the window width minus 2, a mark is displayed at the end of the window to notify the user. As the cursor moves and reaches the window boundaries, the window is centered about the cursor. The mark is a > (right angle bracket) if the line extends on the right side of the window, a < (left angle bracket) if the line extends on the left side of the window, and an * (asterisk) if the line extends on both sides of the window.

[Compaq]  The search commands in each edit mode provide access to the history file. Only strings are matched, not patterns, although if the leading character in the string is a ^ (circumflex), the match is restricted to begin at the first character in the line.
 

The emacs Editing Mode

This mode is entered by enabling either the emacs or gmacs option. The only difference between these two modes is the way they handle <Ctrl-t>. To edit, the user moves the cursor to the point needing correction and then inserts or deletes characters or words as needed. All the editing commands are control characters or escape sequences. The notation for control characters is ^ (circumflex) followed by the character. For example, ^F is the notation for <Ctrl-f>. This is entered by pressing f while holding down <Ctrl>. <Shift> is not depressed. (The notation ^? indicates <Delete>.)

The notation for escape sequences is M- followed by a character. For example, M-f (pronounced Meta f) is entered by pressing <Esc> (ASCII 033) followed by f. (M-F would be the notation for <Esc> followed by <Shift> (capital) F.)

All edit commands operate from any place on the line (not just at the beginning). Do not press <Return> or linefeed after edit commands except when noted. Moves the cursor forward (right) one character. Moves the cursor forward one word. (The emacs editor's definition of a word is a string of characters, consisting of only letters, digits, and underscores, and delimited with spaces or tabs.) Moves the cursor backward (left) one character. Moves the cursor backward one word. Moves the cursor to the start of the line. Moves the cursor to the end of the line. Moves the cursor forward on the current line to the character indicated by the character argument. Moves the cursor backward on the current line to the character indicated by the character argument. Interchanges the cursor and mark. Deletes the previous character. (User-defined Erase character as defined by the stty command, often <Ctrl-h> or #.) Deletes the current character. Deletes the current word. Deletes the previous word. Deletes the previous word. Deletes the previous word (if your Interrupt character is <Delete>, this command does not work). Transposes the current character with next character in emacs mode. Transposes two previous characters in gmacs mode. Capitalizes the current character. Capitalizes the current word. Changes the current word to lowercase. Deletes from the cursor to the end of the line. If preceded by a numerical parameter whose value is less than the current cursor position, deletes from given position up to the cursor. If preceded by a numerical parameter whose value is greater than the current cursor position, deletes from the cursor up to given cursor position. Deletes from the cursor to the mark. Pushes the region from the cursor to the mark on the stack. Kills the entire current line. If two Kill characters are entered in succession, all Kill characters from then on cause a linefeed (useful when using paper terminals). (User-defined Kill character as defined by the stty command, often <Ctrl-g> or @.) Restores the last item removed from the line. (Yanks the item back to the line.) Performs a linefeed and prints the current line. (Null character.) Sets the mark. Sets the mark. Executes the current line (newline). Executes the current line (enter). The End-of-File character is processed as an End-of-File only if the current line is null. Fetches the previous command. Each time <Ctrl-p> is entered, the previous command back in time is accessed. Moves back one line when not on the first line of a multiline command. Fetches the least recent (oldest) history line. Fetches the most recent (youngest) history line. Fetches the next command line. Each time <Ctrl-n> is entered, the next command line forward in time is accessed. Reverses the search history for a previous command line containing string. If an argument of 0 (zero) is given, the search is forward. The string variable is terminated by a <Return> or newline character. If string is preceded by a ^ (circumflex), the matched line must begin with string. If string is omitted, then the next command line containing the most recent string is accessed. In this case, an argument of 0 (zero) reverses the direction of the search. Executes the current line and fetches the next line relative to current line from the history file. (Operate) Defines the numeric parameter (escape). The digits are taken as an argument to the next command. The commands that accept a parameter are <Ctrl-f>, <Ctrl-b>, <Erase>, <Ctrl-c>, <Ctrl-d>, <Ctrl-k>, <Ctrl-r>, <Ctrl-p>, <Ctrl-n>, <Ctrl-]>, <Esc-.>, <Esc-Ctrl-]>, <Esc-_>, <Esc-b>, <Esc-c>, <Esc-d>, <Esc-f>, <Esc-h>, <Esc-l> and <Esc-Ctrl-h>. Your alias list is searched for an alias by the name _letter and if an alias of this name is defined, its value is inserted on the input queue. The letter must not be one of the preceding metafunctions. (Soft-key) [Compaq]  Your alias list is searched for an alias by the name __letter and if an alias of this name is defined, its value is inserted on the input queue (Soft-key). This can be used to program functions keys on many systems. [Compaq]  Same as <Esc-]> letter. The last word of the previous command is inserted on the line. If preceded by a numeric parameter, the value of this parameter determines which word to insert, rather than the last word. Same as the <Esc-.> combination. Attempts file name generation on the current word. An * (asterisk) is appended if the word does not match any file or contain any special pattern characters. File name completion. Replaces the current word with the longest common prefix of all file names matching the current word with an asterisk appended. If the match is unique, a / (slash) is appended if the file is a directory, and a space is appended if the file is not a directory. Lists the files matching current word pattern if an * (asterisk) were appended. Multiplies the argument of the next command by four. Escapes the next character. Editing characters, the user's Erase, Kill, and Interrupt (normally by using <Delete>) characters can be entered in a command line or in a search string if preceded by a \ (backslash). The backslash removes the next character's editing features (if any). Displays the version of the shell. Inserts a # (number sign) at the beginning of the line and executes it. This causes a comment to be inserted in the history file.
 

The vi Editing Mode

There are two typing modes. Initially, when you enter a command you are in the input mode. To edit, the user enters control mode by typing <Esc> (ASCII 033) and moves the cursor to the place needing correction and then inserts or deletes characters or words as needed. Most control commands accept an optional repeat count prior to the command. When in vi mode on most systems, canonical processing is initially enabled and the command is echoed again if the speed is 1200 baud or greater, if it contains any control characters, or if less than 1 second has elapsed since the prompt was printed. The Escape character terminates canonical processing for the remainder of the command and the user can then modify the command line.

[Compaq]  This scheme has the advantages of canonical processing with the type-ahead echoing of raw mode. If the option viraw is also set, the terminal always has canonical processing disabled. This mode is implicit for systems that do not support two alternate End-of-Line delimiters, and can be helpful for certain terminals.
 

Input Edit Commands

By default the editor is in input mode. (User-defined Erase character as defined by the stty command, often <Ctrl-h> or #.) Deletes the previous character. Deletes the previous space-separated word. Terminates the shell. Escapes the next character. Editing characters and the user's Erase or Kill characters can be entered in a command line or in a search string if preceded by a <Ctrl-v>. <Ctrl-v> removes the next character's editing features (if any). Escapes the next Erase or Kill character.
 

Motion Edit Commands

These commands move the cursor: Cursor forward (right) one character. Cursor forward one word. A word is a string of characters delimited by spaces or tabs. Cursor to the beginning of the next word that follows a space. Cursor to the end of the word. Cursor to end of the current space-delimited word. Cursor backward (left) one character. Cursor backward one word. Cursor to the preceding space-delimited word. Cursor to the column count. Finds the next character c in the current line. Finds the previous character c in the current line. Equivalent to f followed by h. Equivalent to F followed by l. Repeats count times, the last single character find command: f, F, t, or T. Reverses the last single character find command count times. Cursor to the start of the line. Cursor to the first nonspace character in the line. Cursor to the end of the line.
 

Search Edit Commands

These commands access your command history. Fetches the previous command. Each time k is entered, the previous command back in time is accessed. Equivalent to k. Fetches the next command. Each time j is entered, the next command forward in time is accessed. Equivalent to j. Fetches the command number count. The default is the least recent history command. Searches backward through history for a previous command containing the specified string. The string variable is terminated by <Return> or a newline character. If the specified string is preceded by a ^ (circumflex), the matched line must begin with string. If string is null, the previous string is used. Same as / (slash) except that the search is in the forward direction. Searches for next match of the last pattern to the / or ? commands. Searches for next match of the last pattern to the / or ? commands, but in reverse direction. Searches the command history for the string entered by the previous / command.
 

Text Modification Edit Commands

These commands modify the line. Enters input mode and enters text after the current character. Appends text to the end of the line. Equivalent to $a. Deletes the current character through the character to which motion would move the cursor, and enters input mode. If motion is c, the entire line is deleted and input mode is entered. Deletes the current character through the end of line, and enters input mode. Equivalent to c$. Equivalent to cc. Deletes the current character through the end of line. Equivalent to d$. Deletes the current character through the character to which motion would move. If motion is d, the entire line is deleted. Enters input mode and inserts text before the current character. Inserts text before the beginning of the line. Equivalent to 0i. Places the previous text modification before the cursor. Places the previous text modification after the cursor. Enters input mode and replaces characters on the screen with the characters you type, overlay fashion. Replaces the count characters, starting at the current cursor position with c and advancing the cursor. Deletes the current character. Deletes the preceding character. Repeats the previous text modification command. Inverts the case of the count characters, starting at the current cursor position and advancing the cursor. Causes the count word of the previous command to be appended and input mode entered. The last word is used if count is omitted. Causes an * (asterisk) to be appended to the current word and file name generation to be attempted. If no match is found, it rings the bell. Otherwise, the word is replaced by the matching pattern and input mode is entered. File name completion. Replaces the current word with the longest common prefix of all file names matching the current word with an * (asterisk) appended. If the match is unique, a / (slash) is appended if the file is a directory; a space is appended if the file is not a directory.
 

Miscellaneous vi Commands

Yanks the current character through the character to which motion would move the cursor and puts the characters into the delete buffer. The text and cursor are unchanged. Yanks from current position to the end of line. Equivalent to y$. Undoes the last text-modifying command. Undoes all the text-modifying commands performed on the line. Returns the command fc -e ${VISUAL:-${EDITOR:-vi}} count in the input buffer. If count is omitted, the current line is used. Performs a linefeed and prints the current line. Effective only in control mode. Executes the current line, regardless of mode (newline). Executes the current line, regardless of mode (enter). Sends the line after inserting a # (number sign) in front of the line. Useful for causing the current line to be inserted in the history without being executed. Lists the file names that match the current word if an * (asterisk) is appended to it. Searches the alias list for an alias by the name _letter . If an alias of this name is defined, its value is inserted in the input queue for processing.
 

Special sh Commands

The following simple commands are executed in the shell process. Input/output redirection is permitted. Unless otherwise indicated, the output is written on file descriptor 1 and the exit status, when there is no syntax error, is 0 (zero).

Commands that are indicated as command1 or command2 are treated specially in the following ways: Parameter assignment lists that precede the command remain in effect when the command completes. I/O redirections are processed after parameter assignments. Errors cause a script that contains the commands so marked to abort. Words, following a command specified as command2 that are in the format of a parameter assignment, are expanded with the same rules as a parameter assignment. This means that ~ (tilde) substitution is performed after the = (equal sign). Word splitting and file name generation are not performed. The command only expands arguments. Reads the complete file and executes the commands. The commands are executed in the current shell environment. The search path specified by PATH is used to find the directory containing file. If any arguments are specified, they become the positional parameters. Otherwise, the positional parameters are unchanged. The exit status is the exit status of the last command executed. See the alias(1) reference page. See the bg(1) reference page. Exits from the enclosing for, while, until, or select loop, if any. If n is specified, breaks n levels. Resumes the next iteration of the enclosing for, while, until, or select loop. If n is specified, resumes at the nth enclosing loop. See the cd(1) reference page. See the echo(1) reference page. The arguments are read as input to the shell and the resulting commands are executed. If argument is given, the command specified by the arguments is executed in place of this shell without creating a new process. Input/output arguments can appear and affect the current process. If no arguments are given, the effect of this command is to modify file descriptors as prescribed by the input/output redirection list. In this case, any file descriptor numbers greater than 2 that are opened with this mechanism are closed when invoking another program. 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, except for a shell which has the ignoreeof option (see set) turned on. The given names are marked for automatic export to the environment of subsequently executed commands. The export -p command outputs the names and values of all exported variables, one per line, in the format: export variable=value See the fc(1) reference page. See the fg(1) reference page. See the getopts(1) reference page. See the hash(1) reference page. [Compaq]  This command is no longer supported. See the loader(5) reference page for information on using shared libraries. See the jobs(1) reference page. Set the kill(1) reference page. Each argument is a separate arithmetic expression to be evaluated. (See Arithmetic Evaluation for a description of arithmetic expression evaluation.) The exit status is 0 (zero) if the value of the last expression is nonzero, and 1 otherwise. See the newgrp(1) reference page. [Compaq]  The shell output mechanism. With no options or with option - or --, the arguments are printed on standard output as described by echo. In raw mode, -R or -r, the escape conventions of echo are ignored. The -R option prints all subsequent arguments and options other than -n.

The -p option causes the arguments to be written to the pipe of the process spawned with |& instead of standard output. The -s option causes the arguments to be written onto the history file instead of standard output. The -u option can be used to specify a 1-digit file descriptor unit number n on which the output is placed. The default is 1. If the -n option is used, no newline is added to the output. [Compaq]  Equivalent to print -r - $PWD. [Compaq]  The shell input mechanism. One line is read and is broken up into fields using the characters in IFS as separators. In raw mode, a \ (backslash) at the end of a line does not signify line continuation. The first field is assigned to the first name, the second field to the second name, and so on, with leftover fields assigned to the last name. The -p option causes the input line to be taken from the input pipe of a process spawned by the shell using |&. If the -s option is present, the input is saved as a command in the history file. The -u option can be used to specify a 1-digit file descriptor unit to read from. The file descriptor can be opened with the exec special command. The default value of n is 0 (zero). If name is omitted, REPLY is used as the default name. The exit status is 0 (zero) unless an End-of-File is encountered. An End-of-File with the -p option causes cleanup for this process so that another can be spawned. If the first argument contains a ? (question mark), the remainder of this word is used as a prompt on standard error when the shell is interactive. The exit status is 0 (zero) unless an End-of-File is encountered. The variables whose names are given are marked read-only. These variables can not be unset or changed by subsequent assignment. The -p option outputs the names and values of all readonly variables, one per line, in the format: readonly variable=value Causes a shell function to return to the invoking script with the return status specified by n. If n is omitted, the return status is that of the last command executed. If return is invoked while not in a function or a . (dot) script, it is the same as an exit. [Compaq]  This command is no longer supported. See the loader(5) reference page for information on using shared libraries. Using + rather than - causes these options to be turned off. These options can also be used upon invocation of the shell. The options for the set command have the following meanings: [Compaq]  Array assignment. Unsets the variable name and assign values sequentially from the list argument. If +A is used, the variable name is not unset first. Automatically exports subsequent parameters that are defined. Causes the shell to notify the user asynchronously of background job completions. Prevent existing files from being overwritten by the shell's > redirection operator; the >| redirection operator overrides this noclobber option for an individual file. If a command has a nonzero exit status, executes the ERR trap, if set, and exits. This mode is disabled while reading profiles. Disables file name generation. Each command becomes a tracked alias when first encountered. [Compaq]  All parameter assignment arguments are placed in the environment for a command, not just those that precede the command name. Background jobs will run in a separate process group and a line will print upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this option is turned on automatically for interactive shells. Reads commands and checks them for syntax errors, but does not execute them. Ignored for interactive shells. The argument can be one of the following option names: Same as a. Same as e. [Compaq]  Runs all background jobs at a lower priority. This is the default mode. [Compaq]  Invokes an emacs-style inline editor for command entry. [Compaq]  Invokes a gmacs-style inline editor for command entry. The shell does not exit on End-of-File. The exit command must be used. [Compaq]  Same as k. [Compaq]  All directory names resulting from file name generation have a trailing / (slash) appended. Same as m. Prevents redirection > from truncating existing files. Requires >| to truncate a file when turned on. Same as n. Same as f. Does not save function definitions in history file. Same as u. [Compaq]  Same as p. Same as v. [Compaq]  Same as h. Invokes, in insert mode, a vi-style inline editor until you press Escape (ASCII 033). This changes to move mode. A return sends the line. [Compaq]  Each character is processed as it is entered in vi mode. Same as x.
[Compaq]  If no option name is supplied, then the current option settings are printed. [Compaq]  Disables processing of the $HOME/.profile file and uses the /etc/suid_profile file instead of the ENV file. This mode is on whenever the effective user ID or group ID is not equal to the real user ID or group ID. Turning this off causes the effective user ID and group ID to be set to the real user ID and group ID. [Compaq]  Sorts the positional parameters. [Compaq]  Exits after reading and executing one command. Treats unset parameters as an error when substituting. Prints shell input lines as they are read. Prints commands and their arguments as they are executed. Unsets x and v options and stops examining arguments for options. Does not change any of the options; useful in setting $1 to a value beginning with -. If no arguments follow this option, the positional parameters are unset.
These options can also be used upon invocation of the shell. The current set of options can be found in $-. Unless -A is specified, the remaining arguments are positional parameters and are assigned, in order, to $1 $2 .... If no arguments are given, the names and values of all named parameters are printed on the standard output. If the only argument is +, the names of all named parameters are printed. The positional parameters from $n+1 ... are renamed $1 ...; the default n is 1. The argument n can be any arithmetic expression that evaluates to a nonnegative number less than or equal to $#. Prints the accumulated user and system times for the shell and for processes run from the shell. The argument variable specifies a command to be read and executed when the shell receives the specified signals. (Note that argument is scanned once when the trap is set and once when the trap is taken.) Each signal can be given as a number or as the name of the signal. Trap commands are executed in order of signal number. Any attempt to set a trap on a signal that was ignored on entry to the current shell is ineffective.
If argument is omitted or is -, all traps associated with signal are reset to their original values. If argument is the null string, signal is ignored by the shell and by the commands it invokes. If signal is ERR, the command argument is executed whenever a command has a nonzero exit status. If signal is DEBUG, argument is executed after each command. If signal is 0 (zero) or EXIT and the trap statement is executed inside the body of a function, the command argument is executed after the function completes. If signal is 0 (zero) or EXIT for a trap set outside any function, the command argument is executed on exit from the shell. The trap command with no variables prints a list of commands associated with each signal number.
Note
Although signal is an optional parameter, using argument without specifying a value for signal will have no effect. This is not considered an error. [Compaq]  Sets attributes and values for shell parameters. When invoked inside a function, a new instance of the parameter name is created. The parameter value and type are restored when the function completes. The following list of attributes can be specified: [Compaq]  The names refer to function names rather than parameter names. No assignments can be made and the only other valid options are -t, -u, and -x. The -t option turns on execution tracing for this function. The -u option causes this function to be marked undefined. The FPATH variable is searched to find the function definition when the function is referenced. The -x option allows the function definition to remain in effect across shell procedures invoked by name. [Compaq]  Provides system-to-hostname file mapping on machines that restrict the set of characters in file names. [Compaq]  Parameter is an integer. This makes arithmetic faster. If n is nonzero, it defines the output arithmetic base; otherwise, the first assignment determines the output base. [Compaq]  All uppercase characters are converted to lowercase. The uppercase -u option is turned off. [Compaq]  Left justifies and removes leading spaces from value. If n is nonzero, it defines the width of the field; otherwise, it is determined by the width of the value of first assignment. When the parameter is assigned, it is filled on the right with spaces or truncated, if necessary, to fit into the field. Leading zeros are removed if the -Z option is also set. The -R option is turned off. [Compaq]  The given names are marked read-only and these names cannot be changed by subsequent assignment. [Compaq]  Right justifies and fills with leading spaces. If n is nonzero, it defines the width of the field; otherwise, it is determined by the width of the value of first assignment. The field is left-filled with spaces or truncated from the end if the parameter is reassigned. The L option is turned off. [Compaq]  Tags the named parameters. Tags are user definable and have no special meaning to the shell. [Compaq]  All lowercase characters are converted to uppercase characters. The lowercase -l option is turned off. [Compaq]  The given names are marked for export. [Compaq]  Right justifies and fills with leading zeros if the first nonspace character is a digit and the -L option was not set. If n is nonzero, it defines the width of the field; otherwise, it is determined by the width of the value of first assignment.
Using + (plus sign) rather than - (dash) causes these options to be turned off. If no name arguments are given but options are specified, a list of names (and optionally the values) of the parameters that have these options set is printed. (Using + rather than - keeps the values from being printed.) If no names and options are given, the names and attributes of all parameters are printed. See the ulimit(1) reference page. See the umask(1) reference page. See the unalias(1) reference page. The variables or functions given by the list of names are unassigned, that is, their values and attributes are erased. Read-only variables cannot be unset. If the -f option is specified, the names refer to function names. If no options or the -v option is specified, the names refer to variables. Unsetting ERRNO, LINENO, MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and _ removes their special meaning even if they are subsequently assigned. See the wait(1) reference page. [Compaq]  For each name, indicates how it would be interpreted if used as a command name. The -v option produces a more verbose report. The -p option does a path search for name even if name is an alias, a function, or a reserved word.
 

Invocation

If the shell is invoked by exec, and the first character of argument zero ($0) is - (dash), the shell is assumed to be a login shell and commands are read from /etc/profile and then from either .profile in the current directory or $HOME/.profile, if either file exists. Next, commands are read from the file named by performing parameter substitution on the value of the ENV environment variable, if the file exists. If the -s option is not present and argument is present, a path search is performed on the first argument to determine the name of the script to execute. The script argument must have read permission and any setuid and getgid settings are ignored. Commands are then read, as described in the following text.

See the OPTIONS section for a complete description of options that can be interpreted by the shell when it is invoked.
 

NOTES

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 will execute the original command. Use the hash command to correct this situation. When the shell encounters the >> characters, it does not open the file in append mode; instead, the shell opens the file for writing and seeks to the end. Failure (nonzero exit status) of a special command preceding a || symbol prevents the list following || from executing. If a command that is a tracked alias is executed, and then 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 -t option of the alias command to correct this situation. Using the fc built-in command within a compound command causes the whole command to disappear from the history file. The built-in .file command reads the whole file before any commands are executed. Therefore, the alias and unalias commands in the file do not apply to any functions defined in the file. Traps are not processed while a job is waiting for a foreground process. Thus, a trap on CHLD is not executed until the foreground job terminates.
 

RETURN VALUES

Errors detected by the shell, such as syntax errors, cause the shell to return a nonzero exit status. Otherwise, the shell returns the exit status of the last command executed. (See also the exit command, described previously.) If the shell is being used noninteractively, execution of the shell file is abandoned. Run-time errors detected by the shell are reported by printing the command or function name and the error condition. If the line number that the error occurred on is greater than 1, the line number is also printed in [ ] (brackets) after the command or function name.
 

FILES

System profile User profile Contains user information Contains the names of available and permitted shells
 

SEE ALSO

Commands: alias(1), bg(1), cat(1), cd(1), chmod(1), csh(1), echo(1), emacs(1), env(1), fc(1), fg(1), hash(1), jobs(1), kill(1), ksh(1), newgrp(1), nice(1), nohup(1), sh(1), sh(1b), stty(1), test(1), time(1), ulimit(1), umask(1) umask(1), unalias(1), vi(1), wait(1)

Functions:  exec(2), fcntl(2), fork(2), ioctl(2), lseek(2), pipe(2), read(2), sigaction(2), signal(2), umask(2), wait(2)

Routines:  ctype(3), rand(3), ulimit(3)

Files:  null(7), passwd(4), shells(4)

Miscellaneous: loader(5)

Standards:  standards(5)


 

Index

NAME
SYNOPSIS
STANDARDS
OPTIONS
DESCRIPTION
Comments
Shell Flow Control Statements
Command Aliasing
Tilde Substitution
Command Substitution
Parameter Substitution
Interpretation of Spaces
File name Generation
Character Classes
Quoting
Arithmetic Evaluation
Prompting
Conditional Expressions
Input/Output
Environment
Functions
Jobs
Signals
Execution
Command Reentry
Inline Editing Options
The emacs Editing Mode
The vi Editing Mode
Input Edit Commands
Motion Edit Commands
Search Edit Commands
Text Modification Edit Commands
Miscellaneous vi Commands
Special sh Commands
Invocation
NOTES
RETURN VALUES
FILES
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 02:42:46 GMT, October 02, 2010