icon Top 9 categories map      RocketAware >


Tips: Browse or Search all pages for efficient awareness of more than 6000 of the most popular reusable and open source applications, functions, libraries, and FAQs.

The "RKT couplings" below include links to source code, updates, additional information, advice, FAQs, and overviews.


Search all pages


By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Integer, Floating point, Matrix, Statistics, Boolean, ...

Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


RocketLink!--> Man page versions: OpenBSD FreeBSD NetBSD Solaris Others

KSH(1)                     OpenBSD Reference Manual                     KSH(1)

     sh - public domain Bourne shell

     sh [-+abCefhiklmnprsuvxX] [-+o option] [[-c command-string [command-name]
        | -s | file ] [argument ...]]

     sh is a reimplementation of the Bourne shell, a command interpreter for
     both interactive and script use.

   Shell startup
     The following options can be specified only on the command line:

     -c command-string
             ksh will execute the command(s) contained in command-string.

     -i      Interactive mode; see below.

     -l      Login shell; see below.

     -s      The shell reads commands from standard input; all non-option ar-
             guments are positional parameters.

     -r      Restricted mode; see below.

     In addition to the above, the options described in the set built-in com-
     mand can also be used on the command line.

     If neither the -c nor the -s option is specified, the first non-option
     argument specifies the name of a file the shell reads commands from. If
     there are no non-option arguments, the shell reads commands from the
     standard input. The name of the shell (i.e., the contents of $0) is de-
     termined as follows: if the -c option is used and there is a non-option
     argument, it is used as the name; if commands are being read from a file,
     the file is used as the name; otherwise, the name the shell was called
     with (i.e., argv[0]) is used.

     A shell is ``interactive'' if the -i option is used or if both standard
     input and standard error are attached to a tty. An interactive shell has
     job control enabled (if available), ignores the SIGINT, SIGQUIT, and
     SIGTERM signals, and prints prompts before reading input (see PS1 and PS2
     parameters).  For non-interactive shells, the trackall option is on by
     default (see set command below).

     A shell is ``restricted'' if the -r option is used or if either the base-
     name of the name the shell was invoked with or the SHELL parameter match
     the pattern ``*r*sh'' (e.g., ``rsh'', ``rksh'', ``rpdksh'', etc.).  The
     following restrictions come into effect after the shell processes any
     profile and ENV files:

     -   The cd command is disabled.
     -   The SHELL, ENV, and PATH parameters cannot be changed.
     -   Command names can't be specified with absolute or relative paths.
     -   The -p option of the built-in command command can't be used.
     -   Redirections that create files can't be used (i.e., `>', `>|', `>>',

     A shell is ``privileged'' if the -p option is used or if the real user ID
     or group ID does not match the effective user ID or group ID (see getu-
     id(2) and getgid(2)).  A privileged shell does not process $HOME/.profile
     nor the ENV parameter (see below). Instead, the file /etc/suid_profile is
     processed. Clearing the privileged option causes the shell to set its ef-
     fective user ID (group ID) to its real user ID (group ID).

     If the basename of the name the shell is called with (i.e., argv[0])
     starts with `-' or if the -l option is used, the shell is assumed to be a
     login shell and the shell reads and executes the contents of /etc/profile
     and $HOME/.profile if they exist and are readable.

     If the ENV parameter is set when the shell starts (or, in the case of lo-
     gin shells, after any profiles are processed), its value is subjected to
     parameter, command, arithmetic, and tilde (`~') substitution and the re-
     sulting file (if any) is read and executed. If the ENV parameter is not
     set (and not NULL) and pdksh was compiled with the DEFAULT_ENV macro de-
     fined, the file named in that macro is included (after the above men-
     tioned substitutions have been performed).

     The exit status of the shell is 127 if the command file specified on the
     command line could not be opened, or non-zero if a fatal syntax error oc-
     curred during the execution of a script. In the absence of fatal errors,
     the exit status is that of the last command executed, or zero, if no com-
     mand is executed.

   Command syntax
     The shells begins parsing its input by breaking it into words. Words,
     which are sequences of characters, are delimited by unquoted whitespace
     characters (space, tab, and newline) or meta-characters (`<', `>', `|',
     `;', `(', and `)'). Aside from delimiting words, spaces and tabs are ig-
     nored, while newlines usually delimit commands. The meta-characters are
     used in building the following tokens: `<', `<&', `<<', `>', `>&', `>>',
     etc. are used to specify redirections (see Input/output redirection be-
     low); `|' is used to create pipelines; `;' is used to separate commands;
     `&' is used to create asynchronous pipelines; `&&' and `||' are used to
     specify conditional execution; `;;' is used in case statements; and last-
     ly, `( .. )' is used to create subshells.

     Whitespace and meta-characters can be quoted individually using a back-
     slash (`\'), or in groups using double (`"') or single (`'') quotes. Note
     that the following characters are also treated specially by the shell and
     must be quoted if they are to represent themselves: `\', `"', `'', `#',
     `$', ``', `~', `{', `}', `*', `?', and `['. The first three of these are
     the above mentioned quoting characters (see Quoting below); `#', if used
     at the beginning of a word, introduces a comment -- everything after the
     `#' up to the nearest newline is ignored; `$' is used to introduce param-
     eter, command, and arithmetic substitutions (see Substitution below); ``'
     introduces an old-style command substitution (see Substitution below);
     `~' begins a directory expansion (see Tilde expansion below); `{' and `}'
     delimit csh(1) style alterations (see Brace expansion below); and final-
     ly, `*', `?', and `[' are used in file name generation (see File name
     patterns below).

     As words and tokens are parsed, the shell builds commands, of which there
     are two basic types: simple-commands, typically programs that are execut-
     ed, and compound-commands, such as for and if statements, grouping con-
     structs and function definitions.

     A simple-command consists of some combination of parameter assignments
     (see Parameters below), input/output redirections (see Input/output
     redirections below), and command words; the only restriction is that pa-
     rameter assignments come before any command words. The command words, if
     any, define the command that is to be executed and its arguments. The
     command may be a shell built-in command, a function or an external com-
     mand (i.e., a separate executable file that is located using the PATH pa-
     rameter (see Command execution below)).  Note that all command constructs
     have an exit status: for external commands, this is related to the status
     returned by wait(2) (if the command could not be found, the exit status
     is 127; if it could not be executed, the exit status is 126); the exit
     status of other command constructs (built-in commands, functions, com-
     pound-commands, pipelines, lists, etc.) are all well-defined and are de-
     scribed where the construct is described. The exit status of a command
     consisting only of parameter assignments is that of the last command sub-
     stitution performed during the parameter assignment or 0 is there were no
     command substitutions.

     Commands can be chained together using the `|' token to form pipelines,
     in which the standard output of each command but the last is piped (see
     pipe(2))  to the standard input of the following command. The exit status
     of a pipeline is that of its last command. A pipeline may be prefixed by
     the `!' reversed word which causes the exit status of the pipeline to be
     logically complemented: if the original status was 0 the complemented
     status will be 1; if the original status was not 0, the complemented sta-
     tus will be 0.

     Lists of commands can be created by separating pipelines by any of the
     following tokens: `&&', `||', `&', `|&', and `;'. The first two are for
     conditional execution: ``cmd1 && cmd2'' executes cmd2 only if the exit
     status of cmd1 is zero; `||' is the opposite -- cmd2 is executed only if
     the exit status of cmd1 is non-zero.  `&&' and `||' have equal precedence
     which is higher that that of `&', `|&' and `;', which also have equal
     precedence. The `&' token causes the preceding command to be executed
     asynchronously; that is, the shell starts the command but does not wait
     for it to complete (the shell does keep track of the status of asyn-
     chronous commands, see Job control below). When an asynchronous command
     is started when job control is disabled (i.e., in most scripts), the com-
     mand is started with signals SIGINT and SIGQUIT ignored and with input
     redirected from /dev/null (however, redirections specified in the asyn-
     chronous command have precedence).  Note that a command must follow the
     `&&' and `||' operators, while it need not follow `&', `|&' or `;'. The
     exit status of a list is that of the last command executed, with the ex-
     ception of asynchronous lists, for which the exit status is 0.

     Compound commands are created using the following reserved words. These
     words are only recognized if they are unquoted and if they are used as
     the first word of a command (i.e., they can't be preceded by parameter
     assignments or redirections):

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

     Note: Some shells (but not this one) execute control structure commands
     in a subshell when one or more of their file descriptors are redirected,
     so any environment changes inside them may fail. To be portable, the exec
     statement should be used instead to redirect file descriptors before the
     control structure.

     In the following compound command descriptions, command lists (denoted as
     list) that are followed by reserved words must end with a semicolon, a
     newline, or a (syntactically correct) reserved word. For example,

     { echo foo; echo bar; }
     { echo foo; echo bar<newline> }
     { { echo foo; echo bar; } }

     are all valid, but

     { echo foo; echo bar }

     is not.

     ( list )
             Execute list in a subshell. There is no implicit way to pass en-

             vironment changes from a subshell back to its parent.

     { list }
             Compound construct; list is executed, but not in a subshell. Note
             that { and } are reserved words, not meta-characters.

     case word in [[(] pattern [| pattern] ... ) list ;; ] ... esac
             The case statement attempts to match word against the specified
             patterns; the list associated with the first successfully matched
             pattern is executed. Patterns used in case statements are the
             same as those used for file name patterns except that the re-
             strictions regarding `.' and `/' are dropped. Note that any un-
             quoted space before and after a pattern is stripped; any space
             with a pattern must be quoted. Both the word and the patterns are
             subject to parameter, command, and arithmetic substitution, as
             well as tilde substitution. For historical reasons, open and
             close braces may be used instead of in and esac (e.g., case $foo
             { *) echo bar; }). The exit status of a case statement is that of
             the executed list; if no list is executed, the exit status is ze-

     for name [in word ... term] do list done
             For each word in the specified word list, the parameter name is
             set to the word and list is executed. If in is not used to speci-
             fy a word list, the positional parameters ($1, $2, etc.)  are
             used instead. For historical reasons, open and close braces may
             be used instead of do and done (e.g., for i; { echo $i; }). The
             exit status of a for statement is the last exit status of list;
             if list is never executed, the exit status is zero.  term is ei-
             ther a newline or a `;'.

     if list then list [elif list then list] ... [else list] fi
             If the exit status of the first list is zero, the second list is
             executed; otherwise, the list following the elif, if any, is exe-
             cuted with similar consequences. If all the lists following the
             if and elifs fail (i.e., exit with non-zero status), the list
             following the else is executed. The exit status of an if state-
             ment is that of non-conditional list that is executed; if no non-
             conditional list is executed, the exit status is zero.

     until list do list done
             This works like while, except that the body is executed only
             while the exit status of the first list is non-zero.

     while list do list done
             A while is a pre-checked loop. Its body is executed as often as
             the exit status of the first list is zero. The exit status of a
             while statement is the last exit status of the list in the body
             of the loop; if the body is not executed, the exit status is ze-

     function name { list }
             Defines the function name (see Functions below). Note that redi-
             rections specified after a function definition are performed
             whenever the function is executed, not when the function defini-
             tion is executed.

     name () command
             Mostly the same as function (see Functions below).

     Quoting is used to prevent the shell from treating characters or words
     specially. There are three methods of quoting. First, `\' quotes the fol-
     lowing character, unless it is at the end of a line, in which case both
     the `\' and the newline are stripped. Second, a single quote (`'') quotes
     everything up to the next single quote (this may span lines). Third, a
     double quote (`"') quotes all characters, except `$', ``' and `\', up to
     the next unquoted double quote.  `$' and ``' inside double quotes have
     their usual meaning (i.e., parameter, command or arithmetic substitution)
     except no field splitting is carried out on the results of double-quoted
     substitutions. If a `\' inside a double-quoted string is followed by `\',
     `$', ``', or `"', it is replaced by the second character; if it is fol-
     lowed by a newline, both the `\' and the newline are stripped; otherwise,
     both the `\' and the character following are unchanged.

     Note: See POSIX mode below for a special rule regarding sequences of the
     form "...`...\"...`..".

     There are two types of aliases: normal command aliases and tracked alias-
     es.  Command aliases are normally used as a short hand for a long or of-
     ten used command. The shell expands command aliases (i.e., substitutes
     the alias name for its value) when it reads the first word of a command.
     An expanded alias is re-processed to check for more aliases. If a command
     alias ends in a space or tab, the following word is also checked for
     alias expansion. The alias expansion process stops when a word that is
     not an alias is found, when a quoted word is found or when an alias word
     that is currently being expanded is found.

     The following command aliases are defined automatically by the shell:

           hash='alias -t'
           type='whence -v'

     Tracked aliases allow the shell to remember where it found a particular
     command. The first time the shell does a path search for a command that
     is marked as a tracked alias, it saves the full path of the command. The
     next time the command is executed, the shell checks the saved path to see
     that it is still valid, and if so, avoids repeating the path search.
     Tracked aliases can be listed and created using alias -t. Note that
     changing the PATH parameter clears the saved paths for all tracked alias-
     es. If the trackall option is set (i.e., set -o trackall or set -h), the
     shell tracks all commands. This option is set automatically for non-in-
     teractive shells. For interactive shells, only the following commands are
     automatically tracked: cat, cc, chmod, cp, date, ed, emacs, grep, ls,
     mail, make, mv, pr, rm, sed, sh, vi, and who.

     The first step the shell takes in executing a simple-command is to per-
     form substitutions on the words of the command. There are three kinds of
     substitution: parameter, command, and arithmetic. Parameter substitu-
     tions, which are described in detail in the next section, take the form
     $name or ${...}; command substitutions take the form $(command) or
     `command`; and arithmetic substitutions take the form $((expression)).

     If a substitution appears outside of double quotes, the results of the
     substitution are generally subject to word or field splitting according
     to the current value of the IFS parameter. The IFS parameter specifies a
     list of characters which are used to break a string up into several
     words; any characters from the set space, tab, and newline that appear in
     the IFS characters are called ``IFS whitespace''. Sequences of one or
     more IFS whitespace characters, in combination with zero or no non-IFS
     whitespace characters, delimit a field. As a special case, leading and
     trailing IFS whitespace is stripped (i.e., no leading or trailing empty
     field is created by it); leading or trailing non-IFS whitespace does cre-
     ate an empty field.

     Example: If IFS is set to ``<space>:'', and VAR is set to
     ``<space>A<space>:<space><space>B::D'', the substitution for $VAR results
     in four fields: ``A'', ``B'', ``'', and ``D''. Note that if the IFS pa-
     rameter is set to the NULL string, no field splitting is done; if the pa-
     rameter is unset, the default value of space, tab, and newline is used.
     Also, note that the field splitting applies only to the immediate result
     of the substitution. Using the previous example, the substitution for
     $VAR:E results in the fields: ``A'', ``B'', ``'', and ``D:E'', not ``A'',
     ``B'', ``'', and ``E''. This behavior is POSIX compliant, but incompati-
     ble with some other shell implementations which do field splitting on the
     word which contained the substitution or use IFS as a general whitespace

     The results of substitution are, unless otherwise specified, also subject
     to brace expansion and file name expansion (see the relevant sections be-

     A command substitution is replaced by the output generated by the speci-
     fied command, which is run in a subshell. For $(command) substitutions,
     normal quoting rules are used when command is parsed; however, for the
     `command` form, a `\' followed by any of `$', ``', or `\' is stripped (a
     `\' followed by any other character is unchanged). As a special case in
     command substitutions, a command of the form < file is interpreted to
     mean substitute the contents of file (note that $(< foo) has the same ef-
     fect as $(cat foo), but it is carried out more efficiently because no
     process is started).

     Note: $(command) expressions are currently parsed by finding the matching
     parenthesis, regardless of quoting. This should be fixed soon.

     Arithmetic substitutions are replaced by the value of the specified ex-
     pression.  For example, the command echo $((2+3*4)) prints 14. See
     Arithmetic expressions for a description of an expression.

     Parameters are shell variables; they can be assigned values and their
     values can be accessed using a parameter substitution. A parameter name
     is either one of the special single punctuation or digit character param-
     eters described below, or a letter followed by zero or more letters or
     digits (`_' counts as a letter). Parameter substitutions take the form
     $name or ${name}, where name is a parameter name. If substitution is per-
     formed on a parameter that is not set, a NULL string is substituted un-
     less the nounset option (set -o nounset or set -u) is set, in which case
     an error occurs.

     Parameters can be assigned valued in a number of ways. First, the shell
     implicitly sets some parameters like #, PWD, etc.; this is the only way
     the special single character parameters are set.  Second, parameters are
     imported from the shell's environment at startup. Third, parameters can
     be assigned values on the command line, for example, FOO=bar sets the pa-
     rameter FOO to ``bar''; multiple parameter assignments can be given on a
     single command line and they can be followed by a simple-command, in
     which case the assignments are in effect only for the duration of the
     command (such assignments are also exported, see below for implications
     of this). Note that both the parameter name and the `=' must be unquoted
     for the shell to recognize a parameter assignment. The fourth way of set-
     ting a parameter is with the export, readonly and typeset commands; see
     their descriptions in the Command execution section. Fifth, for loops set
     parameters as well as the getopts, read and set -A commands. Lastly, pa-
     rameters can be assigned values using assignment operators inside arith-
     metic expressions (see Arithmetic expressions below) or using the
     ${name=value} form of the parameter substitution (see below).

     Parameters with the export attribute (set using the export or typeset -x
     commands, or by parameter assignments followed by simple commands) are
     put in the environment (see environ(5))  of commands run by the shell as
     name=value pairs. The order in which parameters appear in the environment
     of a command is unspecified. When the shell starts up, it extracts param-
     eters and their values from its environment and automatically sets the
     export attribute for those parameters.

     Modifiers can be applied to the ${name} form of parameter substitution:

             If name is set and not NULL, it is substituted; otherwise, word
             is substituted.

             If name is set and not NULL, word is substituted; otherwise,
             nothing is substituted.

             If name is set and not NULL, it is substituted; otherwise, it is
             assigned word and the resulting value of name is substituted.

             If name is set and not NULL, it is substituted; otherwise, word
             is printed on standard error (preceded by name:) and an error oc-
             curs (normally causing termination of a shell script, function or
             .-script). If word is omitted the string ``parameter null or not
             set'' is used instead.

     In the above modifiers, the `:' can be omitted, in which case the condi-
     tions only depend on name being set (as opposed to set and not NULL). If
     word is needed, parameter, command, arithmetic, and tilde substitution
     are performed on it; if word is not needed, it is not evaluated.

     The following forms of parameter substitution can also be used:

             The number of positional parameters if name is `*', `@', not
             specified, or the length of the string value of parameter name.

     ${#name[*]}, ${#name[@]}
             The number of elements in the array name.

     ${name#pattern}, ${name##pattern}
             If pattern matches the beginning of the value of parameter name,
             the matched text is deleted from the result of substitution. A
             single `#' results in the shortest match, and two of them result
             in the longest match.

     ${name%pattern}, ${name%%pattern}
             Like ${..#..} substitution, but it deletes from the end of the

     The following special parameters are implicitly set by the shell and can-
     not be set directly using assignments:

     !        Process ID of the last background process started. If no back-
              ground processes have been started, the parameter is not set.

     #        The number of positional parameters (i.e., $1, $2, etc.).

     $        The process ID of the shell, or the PID of the original shell if
              it is a subshell.

     -        The concatenation of the current single letter options (see set
              command below for list of options).

     ?        The exit status of the last non-asynchronous command executed.
              If the last command was killed by a signal, $? is set to 128
              plus the signal number.

     0        The name the shell was invoked with (i.e., argv[0]), or the
              command-name if it was invoked with the -c option and the
              command-name was supplied, or the file argument, if it was sup-
              plied. If the posix option is not set, $0 is the name of the
              current function or script.

     1 ... 9  The first nine positional parameters that were supplied to the
              shell, function or .-script. Further positional parameters may
              be accessed using ${number}.

     *        All positional parameters (except parameter 0), i.e., $1, $2,
              $3... If used outside of double quotes, parameters are separate
              words (which are subjected to word splitting); if used within
              double quotes, parameters are separated by the first character
              of the IFS parameter (or the empty string if IFS is NULL).

     @        Same as $*, unless it is used inside double quotes, in which
              case a separate word is generated for each positional parameter.
              If there are no positional parameters, no word is generated.  $@
              can be used to access arguments, verbatim, without losing NULL
              arguments or splitting arguments with spaces.

     The following parameters are set and/or used by the shell:

     CDPATH     Search path for the cd built-in command. Works the same way as
                PATH for those directories not beginning with `/' in cd com-
                mands. Note that if CDPATH is set and does not contain ``.''
                or contains an empty path, the current directory is not
                searched. Also, the cd built-in command will display the re-
                sulting directory when a match is found in any search path
                other than the empty path.

     COLUMNS    Set to the number of columns on the terminal or window. Cur-
                rently set to the ``cols'' value as reported by stty(1) if
                that value is non-zero. This parameter is used by set -o and
                kill -l commands to format information columns.

     ENV        If this parameter is found to be set after any profile files
                are executed, the expanded value is used as a shell startup
                file. It typically contains function and alias definitions.

     ERRNO      Integer value of the shell's errno variable. It indicates the
                reason the last system call failed. Not yet implemented.

     EXECSHELL  If set, this parameter is assumed to contain the shell that is
                to be used to execute commands that execve(2) fails to execute
                and which do not start with a ``#!shell'' sequence.

     FCEDIT     The editor used by the fc command (see below).

     FPATH      Like PATH, but used when an undefined function is executed to
                locate the file defining the function. It is also searched
                when a command can't be found using PATH. See Functions below
                for more information.

     HOME       The default directory for the cd command and the value substi-
                tuted for an unqualified ~ (see Tilde expansion below).

     IFS        Internal field separator, used during substitution and by the
                read command, to split values into distinct arguments; normal-
                ly set to space, tab and newline. See Substitution above for

                Note: This parameter is not imported from the environment when
                the shell is started.

                The version of shell and the date the version was created


     LINENO     The line number of the function or shell script that is cur-
                rently being executed.

     LINES      Set to the number of lines on the terminal or window. Not yet

     OLDPWD     The previous working directory. Unset if cd has not success-
                fully changed directories since the shell started, or if the
                shell doesn't know where it is.

     OPTARG     When using getopts, it contains the argument for a parsed op-
                tion, if it requires one.

     OPTIND     The index of the last argument processed when using getopts.
                Assigning 1 to this parameter causes getopts to process argu-
                ments from the beginning the next time it is invoked.

     PATH       A colon separated list of directories that are searched when
                looking for commands and .'d files. An empty string resulting
                from a leading or trailing colon, or two adjacent colons, is
                treated as a ``.'', the current directory.

                If set, this parameter causes the posix option to be enabled.
                See POSIX mode below.

     PPID       The process ID of the shell's parent (read-only).

     PS1        The prompt is printed verbatim (i.e., no substitutions are
                done).  Default is ``$ '' for non-root users, ``# '' for root.

     PS2        Secondary prompt string, by default ``> '', used when more in-
                put is needed to complete a command.

     PS4        Used to prefix commands that are printed during execution
                tracing (see set -x command below). The prompt is printed ver-
                batim (i.e., no substitutions are done). Default is ``+ ''.

     PWD        The current working directory. May be unset or NULL if the
                shell doesn't know where it is.

     REPLY      Default parameter for the read command if no names are given.

     TMPDIR     The directory shell temporary files are created in. If this
                parameter is not set, or does not contain the absolute path of
                a writable directory, temporary files are created in /tmp.

   Tilde expansion
     Tilde expansion, which is done in parallel with parameter substitution,
     is done on words starting with an unquoted `~'. The characters following
     the tilde, up to the first `/', if any, are assumed to be a login name.
     If the login name is empty, `+' or `-', the value of the HOME, PWD, or
     OLDPWD parameter is substituted, respectively. Otherwise, the password
     file is searched for the login name, and the tilde expression is substi-
     tuted with the user's home directory. If the login name is not found in
     the password file or if any quoting or parameter substitution occurs in
     the login name, no substitution is performed.

     In parameter assignments (those preceding a simple-command or those oc-
     curring in the arguments of alias, export, readonly, and typeset), tilde
     expansion is done after any unquoted colon (`:'), and login names are al-
     so delimited by colons.

     The home directory of previously expanded login names are cached and re-
     used.  The alias -d command may be used to list, change and add to this
     cache (e.g., alias -d fac=/usr/local/facilities; cd ~fac/bin).

   File name patterns
     A file name pattern is a word containing one or more unquoted `?' or `*'
     characters or ``[..]'' sequences. Once brace expansion has been per-
     formed, the shell replaces file name patterns with the sorted named of
     all the files that match the pattern (if no files match, the word is left
     unchanged). The pattern elements have the following meaning:

     ?       Matches any single character.

     *       Matches any sequence of characters.

     [..]    Matches any of the characters inside the brackets. Ranges of
             characters can be specified by separating two characters by a `-'
             (e.g., ``[a0-9]'' matches the letter ``a'' or any digit). In or-
             der to represent itself, a `-' must either be quoted or the first
             or last character in the character list.  Similarly, a `]' must
             be quoted or the first character in the list if it is to repre-
             sent itself instead of the end of the list. Also, a `!' appearing
             at the start of the list has special meaning (see below), so to
             represent itself it must be quoted or appear later in the list.

     [!..]   Like [..], except it matches any character not inside the brack-

     Note that pdksh currently never matches ``.'' and ``..'', but the origi-
     nal ksh,  Bourne sh and bash do, so this may have to change (too bad).

     Note that none of the above pattern elements match either a period (`.')
     at the start of a file name or a slash (`/'), even if they are explicitly
     used in a [..] sequence; also, the names ``.'' and ``..'' are never
     matched, even by the pattern ``.*''.

     If the markdirs option is set, any directories that result from file name
     generation are marked with a trailing `/'.

     The POSIX character classes (i.e., [:class-name:] inside a [..] expres-
     sion) are not yet implemented.

   Input/output redirection
     When a command is executed, its standard input, standard output, and
     standard error (file descriptors 0, 1, and 2, respectively) are normally
     inherited from the shell. Three exceptions to this are commands in
     pipelines, for which standard input and/or standard output are those set
     up by the pipeline, asynchronous commands created when job control is
     disabled, for which standard input is initially set to be from /dev/null,
     and commands for which any of the following redirections have been speci-

     > file  Standard output is redirected to file. If file does not exist, it
             is created; if it does exist, is a regular file and the noclobber
             option is set, an error occurs; otherwise, the file is truncated.
             Note that this means the command cmd < foo > foo will open foo
             for reading and then truncate it when it opens it for writing,
             before cmd gets a chance to actually read foo.

     >| file
             Same as >, except the file is truncated, even if the noclobber
             option is set.

     >> file
             Same as >, except if file exists it is appended to instead of be-
             ing truncated. Also, the file is opened in append mode, so writes

             always go to the end of the file (see open(2)).

     < file  Standard input is redirected from file, which is opened for read-

     <> file
             Same as <, except the file is opened for reading and writing.

     << marker
             After reading the command line containing this kind of redirec-
             tion (called a ``here document''), the shell copies lines from
             the command source into a temporary file until a line matching
             marker is read. When the command is executed, standard input is
             redirected from the temporary file. If marker contains no quoted
             characters, the contents of the temporary file are processed as
             if enclosed in double quotes each time the command is executed,
             so parameter, command, and arithmetic substitutions are per-
             formed, along with backslash (`\') escapes for `$', ``', `\', and
             ``\newline''. If multiple here documents are used on the same
             command line, they are saved in order.

     <<- marker
             Same as <<, except leading tabs are stripped from lines in the
             here document.

     <& fd   Standard input is duplicated from file descriptor fd. fd can be a
             single digit, indicating the number of an existing file descrip-
             tor; the letter `p', indicating the file descriptor associated
             with the output of the current co-process; or the character `-',
             indicating standard input is to be closed.

     >& fd   Same as <&, except the operation is done on standard output.

     In any of the above redirections, the file descriptor that is redirected
     (i.e., standard input or standard output) can be explicitly given by pre-
     ceding the redirection with a single digit. Parameter, command, and
     arithmetic substitutions, tilde substitutions, and (if the shell is in-
     teractive) file name generation are all performed on the file, marker and
     fd arguments of redirections. Note, however, that the results of any file
     name generation are only used if a single file is matched; if multiple
     files match, the word with the expanded file name generation characters
     is used. Note that in restricted shells, redirections which can create
     files cannot be used.

     For simple-commands, redirections may appear anywhere in the command; for
     compound-commands (if statements, etc.), any redirections must appear at
     the end. Redirections are processed after pipelines are created and in
     the order they are given, so

     cat /foo/bar 2>&1 > /dev/null | cat -n

     will print an error with a line number prepended to it.

   Arithmetic expressions
     Integer arithmetic expressions can be used with the let command, inside
     $((..)) expressions, inside array references (e.g., name[expr]), as nu-
     meric arguments to the test command, and as the value of an assignment to
     an integer parameter.

     Expressions may contain alpha-numeric parameter identifiers, array refer-
     ences, and integer constants and may be combined with the following C op-
     erators (listed and grouped in increasing order of precedence):

     Unary operators:
           + - ! ~ ++ --

     Binary operators:
           = *= /= %= += -= <<= >>= &= ^= |=
           == !=
           < <= >= >
           << >>
           + -
           * / %

     Ternary operators:
           ?: (precedence is immediately higher than assignment)

     Grouping operators:
           ( )

     Integer constants may be specified with arbitrary bases using the nota-
     tion base#number, where base is a decimal integer specifying the base,
     and number is a number in the specified base.

     The operators are evaluated as follows:

           unary +
                   Result is the argument (included for completeness).

           unary -

           !       Logical NOT; the result is 1 if argument is zero, 0 if not.

           ~       Arithmetic (bit-wise) NOT.

           ++      Increment; must be applied to a parameter (not a literal or
                   other expression).  The parameter is incremented by 1. When
                   used as a prefix operator, the result is the incremented
                   value of the parameter; when used as a postfix operator,
                   the result is the original value of the parameter.

           --      Similar to ++, except the parameter is decremented by 1.

           ,       Separates two arithmetic expressions; the left-hand side is
                   evaluated first, then the right. The result is the value of
                   the expression on the right-hand side.

           =       Assignment; variable on the left is set to the value on the

           *= /= += -= <<= >>= &= ^= |=
                   Assignment operators.   <var> <op> = <expr> is the same as
                   <var> = <var> <op> ( <expr> ).

           ||      Logical OR; the result is 1 if either argument is non-zero,
                   0 if not. The right argument is evaluated only if the left
                   argument is zero.

           &&      Logical AND; the result is 1 if both arguments are non-ze-
                   ro, 0 if not. The right argument is evaluated only if the

                   left argument is non-zero.

           |       Arithmetic (bit-wise) OR.

           ^       Arithmetic (bit-wise) XOR (exclusive-OR).

           &       Arithmetic (bit-wise) AND.

           ==      Equal; the result is 1 if both arguments are equal, 0 if

           !=      Not equal; the result is 0 if both arguments are equal, 1
                   if not.

           <       Less than; the result is 1 if the left argument is less
                   than the right, 0 if not.

           <= >= >
                   Less than or equal, greater than or equal, greater than.
                   See <.

           << >>   Shift left (right); the result is the left argument with
                   its bits shifted left (right) by the amount given in the
                   right argument.

           + - * /
                   Addition, subtraction, multiplication, and division.

           %       Remainder; the result is the remainder of the division of
                   the left argument by the right. The sign of the result is
                   unspecified if either argument is negative.

           <arg1> ? <arg2> : <arg3>
                   If  <arg1> is non-zero, the result is <arg2>, otherwise

     Functions are defined using either Korn shell function name syntax or the
     Bourne/POSIX shell name() syntax (see below for the difference between
     the two forms). Functions are like .-scripts in that they are executed in
     the current environment. However, unlike .-scripts, shell arguments
     (i.e., positional parameters $1, $2, etc.) are never visible inside them.
     When the shell is determining the location of a command, functions are
     searched after special built-in commands, before regular and non-regular
     built-ins, and before the PATH is searched.

     An existing function may be deleted using unset -f function-name. A list
     of functions can be obtained using typeset +f and the function defini-
     tions can be listed using typeset -f. autoload (which is an alias for
     typeset -fu) may be used to create undefined functions; when an undefined
     function is executed, the shell searches the path specified in the FPATH
     parameter for a file with the same name as the function, which, if found,
     is read and executed. If after executing the file the named function is
     found to be defined, the function is executed; otherwise, the normal com-
     mand search is continued (i.e., the shell searches the regular built-in
     command table and PATH). Note that if a command is not found using PATH,
     an attempt is made to autoload a function using FPATH (this is an undocu-
     mented feature of the original Korn shell).

     Functions can have two attributes, ``trace'' and ``export'', which can be
     set with typeset -ft and typeset -fx, respectively. When a traced func-
     tion is executed, the shell's xtrace option is turned on for the func-
     tion's duration; otherwise, the xtrace option is turned off. The
     ``export'' attribute of functions is currently not used. In the original
     Korn shell, exported functions are visible to shell scripts that are exe-
     Since functions are executed in the current shell environment, parameter
     assignments made inside functions are visible after the function com-
     pletes.  If this is not the desired effect, the typeset command can be
     used inside a function to create a local parameter. Note that special pa-
     rameters (e.g., $$, $!) can't be scoped in this way.

     The exit status of a function is that of the last command executed in the
     function. A function can be made to finish immediately using the return
     command; this may also be used to explicitly specify the exit status.

     Functions defined with the function reserved word are treated differently
     in the following ways from functions defined with the () notation:

     -   The $0 parameter is set to the name of the function (Bourne-style
         functions leave $0 untouched).

     -   Parameter assignments preceding function calls are not kept in the
         shell environment (executing Bourne-style functions will keep assign-

     -   OPTIND is saved/reset and restored on entry and exit from the func-
         tion so getopts can be used properly both inside and outside the
         function (Bourne-style functions leave OPTIND untouched, so using
         getopts inside a function interferes with using getopts outside the
         function). In the future, the following differences will also be

               -   A separate trap/signal environment will be used during the
                   execution of functions. This will mean that traps set in-
                   side a function will not affect the shell's traps and sig-
                   nals that are not ignored in the shell (but may be trapped)
                   will have their default effect in a function.

               -   The EXIT trap, if set in a function, will be executed after
                   the function returns.

   POSIX mode
     The shell is intended to be POSIX compliant; however, in some cases,
     POSIX behaviour is contrary either to the original Korn shell behaviour
     or to user convenience. How the shell behaves in these cases is deter-
     mined by the state of the posix option (set -o posix). If it is on, the
     POSIX behaviour is followed; otherwise, it is not. The posix option is
     set automatically when the shell starts up if the environment contains
     the POSIXLY_CORRECT parameter. (The shell can also be compiled so that it
     is in POSIX mode by default; however, this is usually not desirable).

     The following is a list of things that are affected by the state of the
     posix option:

     -   Reading of $ENV. If not in posix mode, the ENV parameter is not ex-
         panded and included when the shell starts.

     -   Occurrences of \" inside double quoted `..` command substitutions. In
         POSIX mode, the \" is interpreted when the command is interpreted; in
         non-POSIX mode, the backslash is stripped before the command substi-
         tution is interpreted. For example, echo "`echo \"hi\"`" produces
         ``"hi"'' in POSIX mode, ``hi'' in non-POSIX mode. To avoid problems,
         use the $(...) form of command substitution.

     -   kill -l output. In POSIX mode, signal names are listed one per line;
         in non-POSIX mode, signal numbers, names and descriptions are printed
         in columns. In future, a new option (-v perhaps) will be added to
         distinguish the two behaviours.

     -   fg exit status. In POSIX mode, the exit status is 0 if no errors oc-
         cur; in non-POSIX mode, the exit status is that of the last fore-

         grounded job.

     -   getopts. In POSIX mode, options must start with a `-'; in non-POSIX
         mode, options can start with either `-' or `+'.

     -   Brace expansion (also known as alternation). In POSIX mode, brace ex-
         pansion is disabled; in non-POSIX mode, brace expansion is enabled.
         Note that set -o posix (or setting the POSIXLY_CORRECT parameter) au-
         tomatically turns the braceexpand option off, although it can be ex-
         plicitly turned on later.

     -   set -. In POSIX mode, this does not clear the verbose or xtrace op-
         tions; in non-POSIX mode, it does.

     -   set exit status. In POSIX mode, the exit status of set is 0 if there
         are no errors; in non-POSIX mode, the exit status is that of any com-
         mand substitutions performed in generating the set command. For exam-
         ple, set -- `false`; echo $? prints 0 in POSIX mode, 1 in non-POSIX
         mode. This construct is used in most shell scripts that use the old
         getopt(1) command.

     -   Argument expansion of alias, export, readonly, and typeset commands.
         In POSIX mode, normal argument expansion is done; in non-POSIX mode,
         field splitting, file globbing, brace expansion, and (normal) tilde
         expansion are turned off, while assignment tilde expansion is turned

     -   Signal specification. In POSIX mode, signals can be specified as dig-
         its, only if signal numbers match POSIX values (i.e., HUP=1, INT=2,
         QUIT=3, ABRT=6, KILL=9, ALRM=14, and TERM=15); in non-POSIX mode,
         signals can always be digits.

     -   Alias expansion. In POSIX mode, alias expansion is only carried out
         when reading command words; in non-POSIX mode, alias expansion is
         carried out on any word following an alias that ended in a space. For
         example, the following for loop

               alias a='for ' i='j'
               a i in 1 2; do echo i=$i j=$j;

         uses parameter i in POSIX mode, j in non-POSIX mode.

     -   Test. In POSIX mode, the expression `-t' (preceded by some number of
         `!' arguments) is always true as it is a non-zero length string; in
         non-POSIX mode, it tests if file descriptor 1 is a tty (i.e., the fd
         argument to the -t test may be left out and defaults to 1).

   Command execution
     After evaluation of command-line arguments, redirections and parameter
     assignments, the type of command is determined:  a special built-in, a
     function, a regular built-in, or the name of a file to execute found us-
     ing the PATH parameter. The checks are made in the above order. Special
     built-in commands differ from other commands in that the PATH parameter
     is not used to find them, and an error during their execution can cause a
     non-interactive shell to exit and parameter assignments that are speci-
     fied before the command are kept after the command completes. Just to
     confuse things, if the posix option is turned off (see set command be-
     low), some special commands are very special in that no field splitting,
     file globbing, brace expansion, nor tilde expansion is performed on argu-
     ments that look like assignments. Regular built-in commands are different
     only in that the PATH parameter is not used to find them.

     The original ksh and POSIX differ somewhat in which commands are consid-
     ered special or regular:

     POSIX special commands

     ., :, break, continue, eval, exec, exit, export, readonly, return, set,
     shift, trap, unset

     Additional ksh special commands

     builtin, times, typeset

     Very special commands (non-POSIX mode)

     alias, readonly, set, typset

     POSIX regular commands

     alias, bg, cd, command, false, fc, fg, getopts, jobs, kill, read, true,
     umask, unalias, wait

     Additional ksh regular commands

     [, echo, let, print, pwd, test, ulimit, whence

     In the future, the additional ksh special and regular commands may be
     treated differently from the POSIX special and regular commands.

     Once the type of the command has been determined, any command-line param-
     eter assignments are performed and exported for the duration of the com-

     The following described the special and regular built-in commands:

     . file [arg1 ...]
             Execute the commands in file in the current environment. The file
             is searched for in the directories of PATH. If arguments are giv-
             en, the positional parameters may be used to access them while
             file is being executed. If no arguments are given, the positional
             parameters are those of the environment the command is used in.

     : [...]
             The null command. Exit status is set to zero.

     alias [-d | +-t [-r]] [+-px] [+-] [name[=value] ...]
              Without arguments, alias lists all aliases. For any name without
             a value, the existing alias is listed.  Any name with a value de-
             fines an alias (see Aliases above).

             When listing aliases, one of two formats is used. Normally,
             aliases are listed as name= value, where value is quoted. If op-
             tions were preceded with `+', or a lone + is given on the command
             line, only name is printed. In addition, if the -p option is
             used, each alias is prefixed with the string ``alias ''.

             The -x option sets (+x clears) the export attribute of an alias,
             or, if no names are given, lists the aliases with the export at-
             tribute (exporting an alias has no effect).

             The -t option indicates that tracked aliases are to be listed/set
             (values specified on the command line are ignored for tracked
             aliases). The -r option indicates that all tracked aliases are to
             be reset.

             The -d option causes directory aliases, which are used in tilde
             expansion, to be listed or set (see Tilde expansion above).

     bg [job ...]
             Resume the specified stopped job(s) in the background. If no jobs
             are specified, %+ is assumed. This command is only available on
             systems which support job control (see Job control below for more

     bind [-m] [key[=editing-command] ...]
              Set or view the current emacs command editing key bind-
             ings/macros (see Emacs interactive input line editing below for a
             complete description).

     break [level]
             Exit the levelth inner-most for, until, or while loop.  level de-
             faults to 1.

     builtin command [arg1 ...]
             Execute the built-in command command.

     cd [-LP] [dir]
             Set the working directory to dir. If the parameter CDPATH is set,
             it lists the search path for the directory containing dir. A NULL
             path means the current directory. If dir is found in any compo-
             nent of the CDPATH search path other than the NULL path, the name
             of the new working directory will be written to standard output.
             If dir is missing, the home directory HOME is used. If dir is
             `-', the previous working directory is used (see OLDPWD parame-
             ter). If the -L option (logical path) is used or if the physical
             option (see set command below) isn't set, references to ``..'' in
             dir are relative to the path used to get to the directory. If the
             -P option (physical path) is used or if the physical option is
             set, ``..'' is relative to the filesystem directory tree. The PWD
             and OLDPWD parameters are updated to reflect the current and old
             working directory, respectively.

     cd [-LP] old new
             The string new is substituted for old in the current directory,
             and the shell attempts to change to the new directory.

     command [-p] cmd [arg1 ...]
             cmd is executed exactly as if command had not been specified,
             with two exceptions. First, cmd cannot be a shell function, and
             second, special built-in commands lose their specialness (i.e.,
             redirection and utility errors do not cause the shell to exit,
             and command assignments are not permanent). If the -p option is
             given, a default search path is used instead of the current value
             of PATH (the actual value of the default path is system depen-
             dent:  on POSIXish systems, it is the value returned by getconf

     continue [level]
             Jumps to the beginning of the levelth inner-most for, until, or
             while loop.  level defaults to 1.

     echo [-neE] [arg ...]
             Prints its arguments (separated by spaces) followed by a newline,
             to the standard output. The newline is suppressed if any of the
             arguments contain the backslash sequence `\c'. See the print com-
             mand below for a list of other backslash sequences that are rec-

             The options are provided for compatibility with BSD shell
             scripts. The -n option suppresses the trailing newline, -e en-
             ables backslash interpretation (a no-op, since this is normally
             done), and -E which suppresses backslash interpretation.

     eval command ...
             The arguments are concatenated (with spaces between them) to form
             a single string which the shell then parses and executes in the

             current environment.

     exec [command [arg ...]]
             The command is executed without forking, replacing the shell pro-

             If no command is given except for I/O redirection, the I/O redi-
             rection is permanent and the shell is not replaced. Any file de-
             scriptors which are opened or dup(2)'d  in this way are made
             available to other executed commands (note that the Korn shell
             differs here: it does not pass on file descriptors greater than

     exit [status]
             The shell exits with the specified exit status. If status is not
             specified, the exit status is the current value of the ? parame-

     export [-p] [parameter[=value]]
             Sets the export attribute of the named parameters. Exported pa-
             rameters are passed in the environment to executed commands. If
             values are specified, the named parameters are also assigned.

             If no parameters are specified, the names of all parameters with
             the export attribute are printed one per line, unless the -p op-
             tion is used, in which case export commands defining all exported
             parameters, including their values, are printed.

     false   A command that exits with a non-zero status.

     fc [-e - | -s] [-g] [old=new] [prefix]
             Re-execute the selected command (the previous command by default)
             after performing the optional substitution of old with new. If -g
             is specified, all occurrences of old are replaced with new. This
             command is usually accessed with the predefined alias r='fx -e

     fg [job ...]
             Resume the specified job(s) in the foreground. If no jobs are
             specified, %+ is assumed. This command is only available on sys-
             tems which support job control (see Job control below for more

     getopts optstring name [arg ...]
             Used by shell procedures to parse the specified arguments (or po-
             sitional parameters, if no arguments are given) and to check for
             legal options.  optstring contains the option letters that
             getopts is to recognize. If a letter is followed by a colon, the
             option is expected to have an argument. Options that do not take
             arguments may be grouped in a single argument. If an option takes
             an argument and the option character is not the last character of
             the argument it is found in, the remainder of the argument is
             taken to be the option's argument; otherwise, the next argument
             is the option's argument.

             Each time getopts is invoked, it places the next option in the
             shell parameter name and the index of the next argument to be
             processed in the shell parameter OPTIND. If the option was intro-
             duced with a `+', the option places in name is prefixed with a
             `+'. When an option requires an argument, getopts places it in
             the shell parameter OPTARG. When an illegal option or a missing
             option argument is encountered, a question mark or a colon is
             placed in name (indicating an illegal option or missing argument,
             respectively) and OPTAG is set to the option character that
             caused the problem. An error message is also printed to standard
             error if optstring does not being with a colon.

             When the end of the options is encountered, getopts exits with a
             non-zero exit status. Options end at the first (non-option argu-
             ment) argument that does not start with a `-', or when a `--' ar-
             gument is encountered.

             Option parsing can be reset by setting OPTIND to 1 (this is done
             automatically whenever the shell or a shell procedure is in-

             Warning: Changing the value of the shell parameter OPTIND to a
             value other than 1, or parsing different sets of arguments with-
             out resetting OPTIND may lead to unexpected results.

     hash [-r] [name ...]
             Without arguments, any hashed executable command pathnames are
             listed. The -r option causes all hashed commands to be removed
             from the hash table. Each name is searched as if it were a com-
             mand name and added to the hash table if it is an executable com-

     jobs [-lpn] [job ...]
             Display information about the specified job(s); if no jobs are
             specified, all jobs are displayed. The -n option causes informa-
             tion to be displayed only for jobs that have changed state since
             the last notification. If the -l option is used, the process ID
             of each process in a job is also listed. The -p option causes on-
             ly the process group of each job to be printed. See Job control
             below for the format of job and the displayed job.

     kill [-s signame | -signum | -signame] { job | pid | pgrp } ...
             Send the specified signal to the specified jobs, process IDs, or
             process groups. If no signal is specified, the TERM signal is
             sent. If a job is specified, the signal is sent to the job's pro-
             cess group. See Job control below for the format of job.

     kill -l [exit-status ...]
             Print the name of the signal that killed a process which exited
             with the specified exit-statuses. If no arguments are specified,
             a list of all the signals, their numbers and a short description
             of them are printed.

     print [-nprsun | -R [-en]] [argument ...]
             print prints its arguments on the standard output, separated by
             spaces and terminated with a newline. The -n option suppresses
             the newline. By default, certain C escapes are translated.  These
             include `\b', `\f', `\n', `\r', `\t', `\v', and `\0###' (`#' is
             an octal digit, of which there may be 0 to 3). `\c' is equivalent
             to using the -n option.  `\' expansion may be inhibited with the
             -r option. The -s option prints to the history file instead of
             standard output, the -u option prints to file descriptor n (n
             defaults to 1 if omitted), and the -p option prints to the co-
             process (see Co-processes above).

             The -R option is used to emulate, to some degree, the BSD echo
             command, which does not process `\' sequences unless the -e op-
             tion is given. As above, the -n option suppresses the trailing

     pwd [-LP]
             Print the present working directory. If the -L option is used or
             if the physical option (see set command below) isn't set, the
             logical path is printed (i.e., the path used to cd to the current
             directory). If the -P option (physical path) is used or if the
             physical option is set, the path determined from the filesystem
             (by following ``..'' directories to the root directory) is print-

     read [-prsun] [parameter ...]
             Reads a line of input from the standard input, separates the line
             into fields using the IFS parameter (see Substitution above), and
             assigns each field to the specified parameters. If there are more
             parameters than fields, the extra parameters are set to NULL, or
             alternatively, if there are more fields than parameters, the last
             parameter is assigned the remaining fields (inclusive of any sep-
             arating spaces). If no parameters are specified, the REPLY param-
             eter is used. If the input line ends in a backslash and the -r
             option was not used, the backslash and the newline are stripped
             and more input is read. If no input is read, read exits with a
             non-zero status.

             The first parameter may have a question mark and a string append-
             ed to it, in which case the string is used as a prompt (printed
             to standard error before any input is read) if the input is a tty
             (e.g., read nfoo?'number of foos: ').

             The -un and -p options cause input to be read from file descrip-
             tor n or the current co-process (see Co-processes above for com-
             ments on this), respectively. If the -s option is used, input is
             saved to the history file.

     readonly [-p] [parameter[=value] ...]
             Sets the read-only attribute of the named parameters. If values
             are given, parameters are set to them before setting the at-
             tribute. Once a parameter is made read-only, it cannot be unset
             and its value cannot be changed.

             If no parameters are specified, the names of all parameters with
             the read-only attribute are printed one per line, unless the -p
             option is used, in which case readonly commands defining all
             read-only parameters, including their values, are printed.

     return [status]
             Returns from a function or . script, with exit status status. If
             no status is given, the exit status of the last executed command
             is used. If used outside of a function or . script, it has the
             same effect as exit. Note that pdksh treats both profile and ENV
             files as . scripts, while the original Korn shell only treats
             profiles as . scripts.

     set [+-abCefhkmnpsuvxX] [+-o option] [+-A name] [--] [arg ...]
             The set command can be used to set (-) or clear (+) shell op-
             tions, set the positional parameters, or set an array parameter.
             Options can be changed using the +-o option syntax, where option
             is the long name of an option, or using the +-letter syntax,
             where letter is the option's single letter name (not all options
             have a single letter name).  The following table lists both op-
             tion letters (if they exist) and long names along with a descrip-
             tion of what the option does:

             -A               Sets the elements of the array parameter name to
                              arg .... If -A is used, the array is reset
                              (i.e., emptied) first; if +A is used, the first
                              N elements are set (where N is the number of
                              args), the rest are left untouched.

             -a allexport     All new parameters are created with the export

             -b notify        Print job notification messages asynchronously,
                              instead of just before the prompt. Only used if

                              job control is enabled (-m).

             -C noclobber     Prevent > redirection from overwriting existing
                              files (>| must be used to force an overwrite).

             -e errexit       Exit (after executing the ERR trap) as soon as
                              an error occurs or a command fails (i.e., exits
                              with a non-zero status). This does not apply to
                              commands whose exit status is explicitly tested
                              by a shell construct such as if, until, while,
                              &&, or || statements.

             -f noglob        Do not expand file name patterns.

             -h trackall      Create tracked aliases for all executed commands
                              (see Aliases above). Enabled by default for non-
                              interactive shells.

             -i interactive   Enable interactive mode. This can only be
                              set/unset when the shell is invoked.

             -k keyword       Parameter assignments are recognized anywhere in
                              a command.

             -l login         The shell is a login shell. This can only be
                              set/unset when the shell is invoked (see Shell
                              startup above).

             -m monitor       Enable job control (default for interactive

             -n -lc -noexec   Do not execute any commands. Useful for checking
                              the syntax of scripts (ignored if interactive).

             -p privileged    Set automatically if, when the shell starts, the
                              read UID or GID does not match the effective UID
                              (EUID) or GID (EGID), respectively. See Shell
                              startup above for a description of what this

             -r restricted    Enable restricted mode. This option can only be
                              used when the shell is invoked.  See Shell
                              startup above for a description of what this

             -s stdin         If used where the shell is invoked, commands are
                              read from standard input. Set automatically if
                              the shell is invoked with no arguments.

                              When -s is used with the set command it causes
                              the specified arguments to be sorted before as-
                              signing them to the positional parameters (or to
                              array name, if -A is used).

             -u nounset       Referencing of an unset parameter is treated as
                              an error, unless one of the `-', `+' or `=' mod-
                              ifiers is used.

             -v verbose       Write shell input to standard error as it is

             -x xtrace        Print commands and parameter assignments when
                              they are executed, preceded by the value of PS4.

             -X markdirs      Mark directories with a trailing `/' during file

                              name generation.

             bgnice           Background jobs are run with lower priority.

             ignoreeof        The shell will not exit when end-of-file is
                              read; exit must be used.

             nohup            Do not kill running jobs with a HUP signal when
                              a login shell exists. Currently set by default,
                              but this will change in the future to be compat-
                              ible with the original Korn shell (which doesn't
                              have this option, but does send the HUP signal).

             nolog            No effect. In the original Korn shell, this pre-
                              vents function definitions from being stored in
                              the history file.

             physical         Causes the cd and pwd commands to use
                              ``physical'' (i.e., the filesystem's) ``..'' di-
                              rectories instead of ``logical'' directories
                              (i.e., the shell handles ``..'', which allows
                              the user to be oblivious of symbolic links to
                              directories). Clear by default. Note that set-
                              ting this option does not affect the current
                              value of the PWD parameter; only the cd command
                              changes PWD. See the cd and pwd commands above
                              for more details.

             posix            Enable POSIX mode. See POSIX mode above.

             vi               Enable vi-like command-line editing (interactive
                              shells only).

             viraw            No effect. In the original Korn shell, unless
                              viraw was set, the vi command-line mode would
                              let the tty driver do the work until ESC (^[)
                              was entered.  pdksh is always in viraw mode.

             vi-esccomplete   In vi command-line editing, do command and file
                              name completion when escape (^[) is entered in
                              command mode.

             vi-show8         Prefix characters with the eighth bit set with
                              ``M-''. If this option is not set, characters in
                              the range 128-160 are printed as is, which may
                              cause problems.

             vi-tabcomplete   In vi command-line editing, do command and file
                              name completion when tab (^I) is entered in in-
                              sert mode.

             These options can also be used upon invocation of the shell. The
             current set of options (with single letter names) can be found in
             the parameter -. set -o with no option name will list all the op-
             tions and whether each is on or off; set +o will print the long
             names of all options that are currently on.

             Remaining arguments, if any, are positional parameters and are
             assigned, in order, to the positional parameters (i.e., $1, $2,
             etc.). If options end with `--' and there are no remaining argu-
             ments, all positional parameters are cleared. If no options or
             arguments are given, the values of all names are printed. For un-
             known historical reasons, a lone `-' option is treated specially

             -- it clears both the -x and -v options.

     shift [number]
             The positional parameters number+1, number+2, etc. are renamed to
             ``1'', ``2'', etc.  number defaults to 1.

     test expression

     [ expression ]
             test evaluates the expression and returns zero status if true, 1
             status if false, or greater than 1 if there was an error. It is
             normally used as the condition command of if and while state-
             ments. The following basic expressions are available:

             str                str has non-zero length. Note that there is
                                the potential for problems if str turns out to
                                be an operator (e.g., -r). It is generally
                                better to use a test like [ X"str" ] instead
                                (double quotes are used in case str contains
                                spaces or file globbing characters).

             -r file            file exists and is readable.

             -w file            file exists and is writable.

             -x file            file exists and is executable.

             -a file            file exists.

             -e file            file exists.

             -f file            file is a regular file.

             -d file            file is a directory.

             -c file            file is a character special device.

             -b file            file is a block special device.

             -p file            file is a named pipe.

             -u file            file's mode has setuid bit set.

             -g file            file's mode has setgid bit set.

             -k file            file's mode has sticky bit set.

             -s file            file is not empty.

             -O file            file's owner is the shell's effective user ID.

             -G file            file's group is the shell's effective group

             -h file            file is a symbolic link.

             -H file            file is a context dependent directory (only
                                useful on HP-UX).

             -L file            file is a symbolic link.

             -S file            file is a socket.

             -o option          Shell option is set (see set command above for
                                a list of options). As a non-standard exten-
                                sion, if the option starts with a `!', the
                                test is negated; the test always fails if
                                option doesn't exist (thus [ -o foo -o -o !foo
                                ] returns true if and only if option foo ex-

             file -nt file      first file is newer than second file.

             file -ot file      first file is older than second file.

             file -ef file      first file is the same file as second file.

             -t [fd]            File descriptor fd is a tty device. If the
                                posix option is not set, fd may be left out,
                                in which case it is taken to be 1 (the be-
                                haviour differs due to the special POSIX rules
                                described below).

             string             string is not empty.

             -z string          string is empty.

             -n string          string is not empty.

             string = string    Strings are equal.

             string != string   Strings are not equal.

             number -eq number  Numbers compare equal.

             number -ne number  Numbers compare not equal.

             number -ge number  Numbers compare greater than or equal.

             number -gt number  Numbers compare greater than.

             number -le number  Numbers compare less than or equal.

             number -lt number  Numbers compare less than.

             The above basic expressions, in which unary operators have prece-
             dence over binary operators, may be combined with the following
             operators (listed in increasing order of precedence):

             expr -o expr  Logical OR.
             expr -a expr  Logical AND.
             ! expr        Logical NOT.
             ( expr )      Grouping.

             On operating systems not supporting /dev/fd/n devices (where n is
             a file descriptor number), the test command will attempt to fake
             it for all tests that operate on files (except the -e test). For
             example, [ -w /dev/fd/2 ] tests if file descriptor 2 is writable.

             Note that some special rules are applied (courtesy of POSIX) if
             the number of arguments to test or [ ... ] is less than five; if
             leading `!' arguments can be stripped such that only one argument
             remains then a string length test is performed (again, even if
             the argument is a unary operator); if leading `!' arguments can
             be stripped such that three arguments remain and the second argu-
             ment is a binary operator, then the binary operation is performed
             (even if the first argument is a unary operator, including an un-
             stripped `!').

             Note: A common mistake is to use if [ $foo = bar ] which fails if
             parameter foo is NULL or unset, if it has embedded spaces (i.e.,
             IFS characters), or if it is a unary operator like `!' or `-n'.

             Use tests like if [ "X$foo" = Xbar ] instead.

     times   Print the accumulated user and system times used by the shell and
             by processes which have exited that the shell started.

     trap [handler signal ...]
             Sets trap handler that is to be executed when any of the speci-
             fied signals are received.  handler is either a NULL string, in-
             dicating the signals are to be ignored, a minus sign (`-'), indi-
             cating that the default action is to be taken for the signals
             (see signal(3)),  or a string containing shell commands to be
             evaluated and executed at the first opportunity (i.e., when the
             current command completes, or before printing the next PS1
             prompt) after receipt of one of the signals.  signal is the name
             of a signal (e.g., PIPE or ALRM) or the number of the signal (see
             kill -l command above). There are two special signals: EXIT (also
             known as 0), which is executed when the shell is about to exit,
             and ERR, which is executed after an error occurs (an error is
             something that would cause the shell to exit if the -e or errexit
             option were see -- see set command above).  EXIT handlers are ex-
             ecuted in the environment of the last executed command. Note that
             for non-interactive shells, the trap handler cannot be changed
             for signals that were ignored when the shell started.

             With no arguments, trap lists, as a series of trap commands, the
             current start of the traps that have been set since the shell

             The original Korn shell's DEBUG trap and the handling of ERR and
             EXIT traps in functions are not yet implemented.

     true    A command that exits with a zero value.

     typeset [[+-Ulprtux] [-L[n]] [-R[n]] [-Z[n]] [-i[n]] | -f [-tux]]
             [name[=value] ...]
             Display or set parameter attributes. With no name arguments, pa-
             rameter attributes are displayed; if no options are used, the
             current attributes of all parameters are printed as typeset com-
             mands; if an option is given (or `-' with no option letter), all
             parameters and their values with the specified attributes are
             printed; if options are introduced with `+', parameter values are
             not printed.

             If name arguments are given, the attributes of the named parame-
             ters are set (-) or cleared (+). Values for parameters may op-
             tionally be specified. If typeset is used inside a function, any
             newly created parameters are local to the function.

             When -f is used, typeset operates on the attributes of functions.
             As with parameters, if no names are given, functions are listed
             with their values (i.e., definitions) unless options are intro-
             duced with `+', in which case only the function names are report-

             -Ln  Left justify attribute.  n specifies the field width. If n
                  is not specified, the current width of a parameter (or the
                  width of its first assigned value) is used. Leading whites-
                  pace (and zeros, if used with the -Z option) is stripped. If
                  necessary, values are either truncated or space padded to
                  fit the field width.

             -Rn  Right justify attribute.  n specifies the field width. If n
                  is not specified, the current width of a parameter (or the
                  width of its first assigned value) is used. Trailing whites-
                  pace is stripped. If necessary, values are either stripped
                  of leading characters or space padded to make them fit the
                  field width.

             -Zn  Zero fill attribute. If not combined with -L, this is the
                  same as -R, except zero padding is used instead of space

             -in  Integer attribute.  n specifies the base to use when dis-
                  playing the integer (if not specified, the base given in the
                  first assignment is used). Parameters with this attribute
                  may be assigned values containing arithmetic expressions.

             -U   Unsigned integer attribute. Integers are printed as unsigned
                  values (only useful when combined with the -i option). This
                  option is not in the original Korn shell.

             -f   Function mode. Display or set functions and their at-
                  tributes, instead of parameters.

             -l   Lower case attribute. All upper case characters in values
                  are converted to lower case. (In the original Korn shell,
                  this parameter meant ``long integer'' when used with the -i

             -p   Print complete typeset commands that can be used to re-cre-
                  ate the attributes (but not the values) or parameters. This
                  is the default action (option exists for ksh93 compatibili-

             -r   Read-only attribute. Parameters with this attribute may not
                  be assigned to or unset. Once this attribute is set, it can
                  not be turned off.

             -t   Tag attribute. Has no meaning to the shell; provided for ap-
                  plication use.

                  For functions, -t is the trace attribute. When functions
                  with the trace attribute are executed, the xtrace (-x) shell
                  option is temporarily turned on.

             -u   Upper case attribute. All lower case characters in values
                  are converted to upper case. (In the original Korn shell,
                  this parameter meant ``unsigned integer'' when used with the
                  -i option, which meant upper case letters would never be
                  used for bases greater than 10. See the -U option.)

                  For functions, -u is the undefined attribute. See Functions
                  above for the implications of this.

             -x   Export attribute. Parameters (or functions) are placed in
                  the environment of any executed commands. Exported functions
                  are not yet implemented.

     ulimit [-acdfHlmnpsStvw] [value]
             Display or set process limits. If no options are used, the file
             size limit (-f) is assumed.  value, if specified, may be either
             an arithmetic expression or the word ``unlimited''. The limits
             affect the shell and any processes created by the shell after a
             limit is imposed. Note that some systems may not allow limits to
             be increased once they are set. Also note that the types of lim-
             its available are system dependent -- some systems have only the
             -f limit.

             -a     Displays all limits; unless -H is used, soft limits are


             -H     Set the hard limit only (default is to set both hard and
                    soft limits).

             -S     Set the soft limit only (default is to set both hard and
                    soft limits).

             -c n   Impose a size limit of n blocks on the size of core dumps.

             -d n   Impose a size limit of n kilobytes on the size of the data

             -f n   Impose a size limit of n blocks on files written by the
                    shell and its child processes (files of any size may be

             -l n   Impose a limit of n kilobytes on the amount of locked
                    (wired) physical memory.

             -m n   Impose a limit of n kilobytes on the amount of physical
                    memory used.

             -n n   Impose a limit of n file descriptors that can be open at

             -p n   Impose a limit of n processes that can be run by the user
                    at any one time.

             -s n   Impose a size limit of n kilobytes on the size of the
                    stack area.

             -t n   Impose a time limit of n CPU seconds to be used by each

             -v n   Impose a limit of n kbytes on the amount of virtual memory
                    used; on some systems this is the maximum allowable virtu-
                    al address (in bytes, not kbytes).

             -w n   Impose a limit of n kbytes on the amount of swap space

             As far as ulimit is concerned, a block is 512 bytes.

     umask [-S] [mask]
             Display or set the file permission creation mask, or umask (see
             umask(2)).  If the -S option is used, the mask displayed or set
             is symbolic; otherwise, it is an octal number.

             Symbolic masks are like those used by chmod(1).  When used, they
             describe what permissions may be made available (as opposed to
             octal masks in which a set bit means the corresponding bit is to
             be cleared).  For example, ``ug=rwx,o='' sets the mask so files
             with not be readable, writable or executable by ``others'', and
             is equivalent (on most systems) to the octal mask ``007''.

     unalias [-adt] [name1 ...]
             The aliases for the given names are removed. If the -a option is
             used, all aliases are removed. If the -t or -d options are used,
             the indicated operations are carried out on tracked or directory
             aliases, respectively.

     unset [-fv] parameter ...
             Unset the named parameters (-v, the default) or functions (-f).
             The exit status is non-zero if any of the parameters were already

             unset, zero otherwise.

     wait [job ...]
             Wait for the specified job(s) to finish. The exit status of wait
             is that of the last specified job; if the last job is killed by a
             signal, the exit status is 128 + the number of the signal (see
             kill -l exit-status above); if the last specified job can't be
             found (because it never existed, or had already finished), the
             exit status of wait is 127. See Job control below for the format
             of job. wait will return if a signal for which a trap has been
             set is received, or if a HUP, INT or QUIT signal is received.

             If no jobs are specified, wait waits for all currently running
             jobs (if any) to finish and exits with a zero status. If job mon-
             itoring is enabled, the completion status of jobs is printed
             (this is not the case when jobs are explicitly specified).

     whence [-pv] [name ...]
             For each name, the type of command is listed (reserved word,
             built-in, alias, function, tracked alias, or executable). If the
             -p option is used, a path search is performed even if name is a
             reserved word, alias, etc. Without the -v option, whence is simi-
             lar to command -v except that whence will find reserved words and
             won't print aliases as alias commands. With the -v option, whence
             is the same as command -V. Note that for whence, the -p option
             does not affect the search path used, as it does for command. If
             the type of one or more of the names could not be determined, the
             exit status is non-zero.

   Job control
     Job control refers to the shell's ability to monitor and control jobs,
     which are processes or groups of processes created for commands or
     pipelines. At a minimum, the shell keeps track of the status of the back-
     ground (i.e., asynchronous) jobs that currently exist; this information
     can be displayed using the jobs commands. If job control is fully enabled
     (using set -m or set -o monitor), as it is for interactive shells, the
     processes of a job are placed in their own process group. Foreground jobs
     can be stopped by typing the suspend character from the terminal (normal-
     ly ^Z), jobs can be restarted in either the foreground or background us-
     ing the fg and bg commands, and the state of the terminal is saved or re-
     stored when a foreground job is stopped or restarted, respectively.

     Note that only commands that create processes (e.g., asynchronous com-
     mands, subshell commands, and non-built-in, non-function commands) can be
     stopped; commands like read cannot be.

     When a job is created, it is assigned a job number. For interactive
     shells, this number is printed inside ``[..]'', followed by the process
     IDs of the processes in the job when an asynchronous command is run. A
     job may be referred to in bg, fg, jobs, kill, and wait commands either by
     the process ID of the last process in the command pipeline (as stored in
     the $! parameter) or by prefixing the job number with a percent sign
     (`%'). Other percent sequences can also be used to refer to jobs:

     %+          The most recently stopped job, or, if there are no stopped
                 jobs, the oldest running job.

     %%, %       Same as %+.

     %-          The job that would be the %+ job if the latter did not exist.

     %n          The job with job number n.

     %?string    The job containing the string string (an error occurs if mul-

                 tiple jobs are matched).

     %string     The job starting with string string (an error occurs if mul-
                 tiple jobs are matched).

     When a job changes state (e.g., a background job finishes or foreground
     job is stopped), the shell prints the following status information:

     [ number ] flag status command


     number  is the job number of the job.

     flag    is the `+' or `-' character if the job is the %+ or %- job, re-
             spectively, or space if it is neither.

     status  indicates the current state of the job and can be:

             Running  The job has neither stopped nor exited (note that run-
                      ning does not necessarily mean consuming CPU time -- the
                      process could be blocked waiting for some event).

             Done [number]
                      The job exited.  number is the exit status of the job,
                      which is omitted if the status is zero.

             Stopped [signal]
                      The job was stopped by the indicated signal (if no sig-
                      nal is given, the job was stopped by SIGTSTP).

             signal-description [``core dumped'']
                      The job was killed by a signal (e.g., memory fault,
                      hangup, etc.; use kill -l for a list of signal descrip-
                      tions). The ``core dumped'' message indicates the pro-
                      cess created a core file.

             is the command that created the process. If there are multiple
             processes in the job, each process will have a line showing its
             command and possibly its status, if it is different from the sta-
             tus of the previous process.

     When an attempt is made to exit the shell while there are jobs in the
     stopped state, the shell warns the user that there are stopped jobs and
     does not exit.  If another attempt is immediately made to exit the shell,
     the stopped jobs are sent a HUP signal and the shell exits. Similarly, if
     the nohup option is not set and there are running jobs when an attempt is
     made to exit a login shell, the shell warns the user and does not exit.
     If another attempt is immediately made to exit the shell, the running
     jobs are sent a HUP signal and the shell exits.


     awk(1),  csh(1),  ed(1),  getconf(1),  getopt(1),  ksh(1),  sed(1),
     stty(1),  vi(1),  dup(2),  execve(2),  getgid(2),  getuid(2),  open(2),
     pipe(2),  wait(2),  getopt(3),  rand(3),  signal(3),  system(3),  envi-

     Morris Bolsky and David Korn, The KornShell Command and Programming
     Language, 1983, ISBN 0-13-516972-0.

     Stephen G. Kochan and Patrick H. Wood, UNIX Shell Programming, Hayden.

     IEEE Inc., IEEE Standard for Information Technology - Portable Operating
     System Interface (POSIX) - Part 2: Shell and Utilities, 1993, ISBN

     sh is implemented as a run-time option of pdksh, with only those ksh fea-
     tures whose syntax or semantics are incompatible with a traditional
     Bourne shell disabled. Since this leaves some ksh extensions exposed,
     caution should be used where backwards compatibility with traditional
     Bourne or POSIX compliant shells is an issue.

     Any bugs in pdksh should be reported to pdksh@cs.mun.ca. Please include
     the version of pdksh (echo $KSH_VERSION shows it), the machine, operating
     system and compiler you are using and a description of how to repeat the
     bug (a small shell script that demonstrates the bug is best).  The fol-
     lowing, if relevant (if you are not sure, include them), can also be
     helpful: options you are using (both options.h and set -o options) and a
     copy of your config.h (the file generated by the configure script). New
     version of pdksh can be obtained from ftp://ftp.cs.mun.ca/pub/pdksh.

     BTW, the most frequently reported bug is:

           echo hi | read a; echo $a   # Does not print hi

     I'm aware of this and there is no need to report it.

     This shell is based on the public domain 7th edition Bourne shell clone
     by Charles Forsyth and parts of the BRL shell by Doug A. Gwyn, Doug
     Kingston, Ron Natalie, Arnold Robbins, Lou Salkind, and others. The first
     release of pdksh was created by Eric Gisin, and it was subsequently main-
     tained by John R.  MacMillan (change!john@sq.sq.com) and Simon J. Gerraty
     (sjg@zen.void.oz.au).  The current maintainer is Michael Rendell
     (michael@cs.mun.ca). The CONTRIBUTORS file in the source distribution
     contains a more complete list of people and their part in the shell's de-

OpenBSD 2.6                     August 19, 1996                             30

Source: OpenBSD 2.6 man pages. Copyright: Portions are copyrighted by BERKELEY
SOFTWARE DESIGN, INC., The Regents of the University of California, Massachusetts
Institute of Technology, Free Software Foundation, FreeBSD Inc., and others.

(Corrections, notes, and links courtesy of RocketAware.com)

[Detailed Topics]
FreeBSD Sources for sh(1)
FreeBSD Sources for sh(1)
OpenBSD sources for sh(1)

[Overview Topics]

Up to: Command Shells and Scripting Languages

RocketLink!--> Man page versions: OpenBSD FreeBSD NetBSD Solaris Others

Rapid-Links: Search | About | Comments | Submit Path: RocketAware > sh.1/
RocketAware.com is a service of Mib Software
Copyright 1999, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments