| KSH(1) | USER COMMANDS | KSH(1) |
|---|
A blank is a tab or a space. An identifier is a sequence of letters, digits, or underscores starting with a letter or underscore. Identifiers are used as components of variable names. A vname is a sequence of one or more identifiers separated by a . and optionally preceded by a .. Vnames are used as function and variable names. A word is a sequence of characters from the character set defined by the current locale, excluding non-quoted metacharacters.
A command is a sequence of characters in the syntax of the shell language. The shell reads each command and carries out the desired action either directly or by invoking separate utilities. A built-in command is a command that is carried out by the shell itself without creating a separate process. Some commands are built-in purely for convenience and are not documented here. Built-ins that cause side effects in the shell environment and built-ins that are found before performing a path search (see Execution below) are documented here. For historical reasons, some of these built-ins behave differently than other built-ins and are called special built-ins.
A
pipeline
is a sequence of one or more
commands
separated by
|.
The standard output of each command but the last
is connected by a
A list is a sequence of one or more pipelines separated by ;, &, |&, &&, or | |, and optionally terminated by ;, &, or |&. Of these five symbols, ;, &, and |& have equal precedence, which is lower than that of && and | |. The symbols && and | | also have equal precedence. A semicolon (;) causes sequential execution of the preceding pipeline; an ampersand (&) causes asynchronous execution of the preceding pipeline (i.e., the shell does not wait for that pipeline to finish). The symbol |& causes asynchronous execution of the preceding pipeline with a two-way pipe established to the parent shell; the standard input and output of the spawned pipeline can be written to and read from by the parent shell by applying the redirection operators <& and >& with arg p to commands and by using -p option of the built-in commands read and print described later. The symbol && ( | | ) causes the list following it to be executed only if the preceding pipeline returns a zero (non-zero) value. One or more new-lines may appear in a list instead of a semicolon, to delimit a command. The first item of the first pipeline of a list that is a simple command not beginning with a redirection, and not occurring within a while, until, or if list, can be preceded by a semicolon. This semicolon is ignored unless the showme option is enabled as described with the set built-in below.
A command is either a simple-command or one of the following. Unless otherwise stated, the value returned by a command is that of the last simple-command executed in the command.
The following reserved words are recognized as reserved only when they are the first word of a command and are not quoted:
In addition, a += can be used in place of the = to signify adding to or appending to the previous value. When += is applied to an arithmetic type, word is evaluated as an arithmetic expression and added to the current value. When applied to a string variable, the value defined by word is appended to the value. For compound assignments, the previous value is not unset and the new values are appended to the current ones provided that the types are compatible.
The right hand side of a variable assignment undergoes all the expansion list below except word splitting, brace expansion, and file name generation. When the left hand side is an assignment is a compound variable and the right hand is the name of a compound variable, the compound variable on the right will be copied or appended to the compound variable on the left.
Aliasing is performed when scripts are read, not while they are executed. Therefore, for an alias to take effect, the alias definition command has to be executed before the command which references the alias is read.
The following aliases are compiled into the shell but can be unset or redefined:
In addition, when expanding a variable assignment, tilde substitution is attempted when the value of the assignment begins with a ~, and when a ~ appears after a :. The : also terminates a ~ login name.
cuts
fields 1 and 3 from
the files
file1
and
file2
respectively,
pastes
the results together, and
sends it
to the processes
process1
and
process2,
as well as putting it onto the standard output.
Note that the file, which is passed as an argument to the command,
is a UNIX
Process substitution of the form <(list ) can also be used with the < redirection operator which causes the output of list to be standard input or the input for whatever file descriptor is specified.
The shell supports both indexed and associative arrays. An element of an array variable is referenced by a subscript. A subscript for an indexed array is denoted by an arithmetic expression (see Arithmetic evaluation below) between a [ and a ]. To assign values to an indexed array, use vname=(value . . .) or set -A vname value . . . . The value of all non-negative subscripts must be in the range of 0 through 4,194,303. A negative subscript is treated as an offset from the maximum current index +1 so that -1 refers to the last element. Indexed arrays can be declared with the -a option to typeset. Indexed arrays need not be declared. Any reference to a variable with a valid subscript is legal and an array will be created if necessary.
An associative array is created with the -A option to typeset. A subscript for an associative array is denoted by a string enclosed between [ and ].
Referencing any array without a subscript is equivalent to referencing the array with subscript 0.
The value of a variable may be assigned by writing:
or
Note that no space is allowed before or after the =.
A nameref is a variable that is a reference to another variable. A nameref is created with the -n attribute of typeset. The value of the variable at the time of the typeset command becomes the variable that will be referenced whenever the nameref variable is used. The name of a nameref cannot contain a .. When a variable or function name contains a ., and the portion of the name up to the first . matches the name of a nameref, the variable referred to is obtained by replacing the nameref portion with the name of the variable referenced by the nameref. If a nameref is used as the index of a for loop, a name reference is established for each item in the list. A nameref provides a convenient way to refer to the variable inside a function whose name is passed as an argument to a function. For example, if the name of a variable is passed as the first argument to a function, the command
inside the function causes references and assignments to var to be references and assignments to the variable whose name has been passed to the function.
If any of the floating point attributes, -E, -F, or -X, or the integer attribute, -i, is set for vname, then the value is subject to arithmetic evaluation as described below.
Positional parameters, parameters denoted by a number, may be assigned values with the set special built-in command. Parameter $0 is set from argument zero when the shell is invoked.
The character $ is used to introduce substitutable parameters.
In the above, word is not evaluated unless it is to be used as the substituted string, so that, in the following example, pwd is executed only if d is not set or is null:
If the colon ( : ) is omitted from the above expressions, then the shell only checks whether parameter is set or not.
The following parameters are automatically set by the shell:
The following variables are used by the shell:
The shell gives default values to
PATH, PS1, PS2,
PS3, PS4, MAILCHECK, FCEDIT,
TMOUT and IFS,
while
HOME,
SHELL,
ENV,
and
MAIL
are
not set at all by the shell (although
HOME
is
set by
login(1)).
On some systems
MAIL
and
SHELL
are also
set by
If the braceexpand (-B) option is set then each of the fields resulting from IFS are checked to see if they contain one or more of the brace patterns {*,*}, {l1..l2} , {n1..n2} , {n1..n2% fmt} , {n1..n2 ..n3} , or {n1..n2 ..n3%fmt} , where * represents any character, l1 ,l2 are letters and n1 ,n2 ,n3 are signed numbers and fmt is a format specified as used by printf. In each case, fields are created by prepending the characters before the { and appending the characters after the } to each of the strings generated by the characters between the { and }. The resulting fields are checked to see if they have any brace patterns.
In the first form, a field is created for each string between { and ,, between , and ,, and between , and }. The string represented by * can contain embedded matching { and } without quoting. Otherwise, each { and } with * must be quoted.
In the seconds form, l1 and l2 must both be either upper case or both be lower case characters in the C locale. In this case a field is created for each character from l1 thru l2 .
In the remaining forms, a field is created for each number starting at n1 and continuing until it reaches n2 incrementing n1 by n3 . The cases where n3 is not specified behave as if n3 where 1 if n1<=n2 and -1 otherwise. If forms which specify %fmt any format flags, widths and precisions can be specified and fmt can end in any of the specifiers cdiouxX. For example, {a,z}{1..5..3%02d}{b..c}x expands to the 8 fields, a01bx, a01cx, a04bx, a04cx, z01bx, z01cx, z04bx and z4cx.
A pattern-list is a list of one or more patterns separated from each other with a & or |. A & signifies that all patterns must be matched whereas | requires that only one pattern be matched. Composite patterns can be formed with one or more of the following sub-patterns:
By default, each pattern, or sub-pattern will match the longest string possible consistent with generating the longest overall match. If more than one match is possible, the one starting closest to the beginning of the string will be chosen. However, for each of the above compound patterns a - can be inserted in front of the ( to cause the shortest match to the specified pattern-list to be used.
When pattern-list is contained within parentheses, the backslash character \ is treated specially even when inside a character class. All ANSI-C character escapes are recognized and match the specified character. In addition the following escape sequences are recognized:
A pattern of the form %(pattern-pair (s)) is a sub-pattern that can be used to match nested character expressions. Each pattern-pair is a two character sequence which cannot contain & or |. The first pattern-pair specifies the starting and ending characters for the match. Each subsequent pattern-pair represents the beginning and ending characters of a nested group that will be skipped over when counting starting and ending character matches. The behavior is unspecified when the first character of a pattern-pair is alpha-numeric except for the following:
Thus, %( { }Q"E\ ), matches characters starting at { until the matching } is found not counting any { or } that is inside a double quoted string or preceded by the escape character \. Without the { } this pattern matches any C language string.
Each sub-pattern in a composite pattern is numbered, starting at 1, by the location of the ( within the pattern. The sequence \n , where n is a single digit and \n comes after the n-th. sub-pattern, matches the same string as the sub-pattern itself.
Finally a pattern can contain sub-patterns of the form ~(options :pattern-list ), where either options or :pattern-list can be omitted. Unlike the other compound patterns, these sub-patterns are not counted in the numbered sub-patterns. If options is present, it can consist of one or more of the following:
If both options and :pattern-list are specified, then the options apply only to pattern-list . Otherwise, these options remain in effect until they are disabled by a subsequent ~(... ) or at the end of the sub-pattern containing ~(... ).
Inside double quote marks (" "), parameter and command substitution occur and \ quotes the characters \, `, ", and $. A $ in front of a double quoted string will be ignored in the "C" or "POSIX" locale, and may cause the string to be replaced by a locale specific string otherwise. The meaning of $* and $@ is identical when not quoted or when used as a variable assignment value or as a file name. However, when used as a command argument, "$*" is equivalent to "$1d $2d . . .", where d is the first character of the IFS variable, whereas "$@" is equivalent to "$1" "$2" . . . . Inside grave quote marks (` `), \ quotes the characters \, `, and $. If the grave quotes occur within double quotes, then \ also quotes the character ".
The special meaning of reserved words or aliases can be removed by quoting any character of the reserved word. The recognition of function names or built-in command names listed below cannot be altered by quoting them.
An arithmetic expression uses the same syntax, precedence, and associativity of expression as the C language. All the C language operators that apply to floating point quantities can be used. In addition, the operator ** can be used for exponentiation. It has higher precedence than multiplication and is left associative. In addition, when the value of an arithmetic variable or sub-expression can be represented as a long integer, all C language integer arithmetic operations can be performed. Variables can be referenced by name within an arithmetic expression without using the parameter expansion syntax. When a variable is referenced, its value is evaluated as an arithmetic expression.
Any of the following math library functions that are in the C math library can be used within an arithmetic expression:
An internal representation of a variable as a double precision floating point can be specified with the -E [ n ], -F [ n ], or -X [ n ] option of the typeset special built-in command. The -E option causes the expansion of the value to be represented using scientific notation when it is expanded. The optional option argument n defines the number of significant figures. The -F option causes the expansion to be represented as a floating decimal number when it is expanded. The -X option cause the expansion to be represented using the %a format defined by ISO C-99. The optional option argument n defines the number of places after the decimal (or radix) point in this case.
An internal integer representation of a variable can be specified with the -i [ n ] option of the typeset special built-in command. The optional option argument n specifies an arithmetic base to be used when expanding the variable. If you do not specify an arithmetic base, base 10 will be used.
Arithmetic evaluation is performed on the value of each assignment to a variable with the -E, -F, -X, or -i attribute. Assigning a floating point number to a variable whose type is an integer causes the fractional part to be truncated.
The following obsolete arithmetic comparisons are also permitted:
In each of the above expressions, if file is of the form /dev/fd/n, where n is an integer, then the test is applied to the open file whose descriptor number is n.
A compound expression can be constructed from these primitives by using any of the following, listed in decreasing order of precedence.
In each of the following redirections, if file is of the form /dev/sctp/host/port, /dev/tcp/host/port, or /dev/udp/host/port, where host is a hostname or host address, and port is a service given by name or an integer port number, then the redirection attempts to make a tcp, sctp or udp connection to the corresponding socket.
No intervening space is allowed between the characters of redirection operators.
If one of the above is preceded by a digit, with no intervening space, then the file descriptor number referred to is that specified by the digit (instead of the default 0 or 1). If one of the above, other than >&- and the ># and <# forms, is preceded by {varname} with no intervening space, then a file descriptor number > 10 will be selected by the shell and stored in the variable varname. If >&- or the any of the ># and <# forms is preceded by {varname} the value of varname defines the file descriptor to close or position. For example:
means file descriptor 2 is to be opened for writing as a duplicate of file descriptor 1 and
means open file named file for reading and store the file descriptor number in variable n.
The order in which redirections are specified is significant. The shell evaluates each redirection in terms of the (file descriptor, file) association at the time of evaluation. For example:
first associates file descriptor 1 with file fname . It then associates file descriptor 2 with the file associated with file descriptor 1 (i.e. fname ). If the order of redirections were reversed, file descriptor 2 would be associated with the terminal (assuming file descriptor 1 had been) and then file descriptor 1 would be associated with file fname .
If a command is followed by & and job control is not active, then the default standard input for the command is the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications.
The environment for any simple-command or function may be augmented by prefixing it with one or more variable assignments. A variable assignment argument is a word of the form identifier=value. Thus:
are equivalent (as far as the above execution of cmd is concerned except for special built-in commands listed below - those that are preceded with a dagger).
If the obsolete -k option is set, all variable assignment arguments are placed in the environment, even if they occur after the command name. The following first prints a=b c and then c:
echo a=b c set -k echo a=b c
This feature is intended for use with scripts written for early versions of the shell and its use in new scripts is strongly discouraged. It is likely to disappear someday.
For historical reasons, there are two ways to define functions, the name( ) syntax and the function name syntax, described in the Commands section above. Shell functions are read in and stored internally. Alias names are resolved when the function is read. Functions are executed like commands with the arguments passed as positional parameters. (See Execution below.)
Functions defined by the function name syntax and called by name execute in the same process as the caller and share all files and present working directory with the caller. Traps caught by the caller are reset to their default action inside the function. A trap condition that is not caught or ignored by the function causes the function to terminate and the condition to be passed on to the caller. A trap on EXIT set inside a function is executed in the environment of the caller after the function completes. Ordinarily, variables are shared between the calling program and the function. However, the typeset special built-in command used within a function defines local variables whose scope includes the current function. They can be passed to functions that they call in the variable assignment list that precedes the call or as arguments passed as name references. Errors within functions return control to the caller.
Functions defined with the name( ) syntax and functions defined with the function name syntax that are invoked with the . special built-in are executed in the caller's environment and share all variables and traps with the caller. Errors within these function executions cause the script that contains them to abort.
The special built-in command return is used to return from function calls.
Function names can be listed with the -f or +f option of the typeset special built-in command. The text of functions, when available, will also be listed with -f. Functions can be undefined with the -f option of the unset special built-in command.
Ordinarily, functions are unset when the shell executes a shell script. Functions that need to be defined across separate invocations of the shell should be placed in a directory and the FPATH variable should contain the name of this directory. They may also be specified in the ENV file.
The variable .sh.name contains the name of the variable for which the discipline function is called, .sh.subscript is the subscript of the variable, and .sh.value will contain the value being assigned inside the set discipline function. The variable _ is a reference to the variable including the subscript if any. For the set discipline, changing .sh.value will change the value that gets assigned. Finally, the expansion ${var .name }, when name is the name of a discipline, and there is no variable of this name, is equivalent to the command substitution ${ var .name ;}.
When a type is defined a special built-in command of that name is added. These built-ins are declaration commands and follow the same expansion rules as all the special built-in commands defined below that are preceded by §§. These commands can subsequently be used inside further type definitions. The man page for these commands can be generated by using the --man option or any of the other -- options described with getopts. The -r, -a, -A, -h, and -S options of typeset are permitted with each of these new built-ins.
An instance of a type is created by invoking the type name followed by one or more instance names. Each instance of the type is initialized with a copy of the sub-variables except for sub-variables that are defined with the -S option. Variables defined with the -S are shared by all instances of the type. Each instance can change the value of any sub-variable and can also define new discipline functions of the same names as those defined by the type definition as well as any standard discipline names. No additional sub-variables can be defined for any instance.
When defining a type, if the value of a sub-variable is not set and the -r attribute is specified, it causes the sub-variable to be a required sub-variable. Whenever an instance of a type is created, all required sub-variables must be specified. These sub-variables become readonly in each instance.
When unset is invoked on a sub-variable within a type, and the -r attribute has not been specified for this field, the value is reset to the default value associative with the type. Invoking unset on a type instance not contained within another type deletes all sub-variables and the variable itself.
A type definition can be derived from another type definition by defining the first sub-variable name as _ and defining its type as the base type. Any remaining definitions will be additions and modifications that apply to the new type. If the new type name is the same is that of the base type, the type will be replaced and the original type will no longer be accessible.
If the monitor option of the set command is turned on, an interactive shell associates a job with each pipeline. It keeps a table of current jobs, printed by the jobs command, and assigns them small integer numbers. When a job is started asynchronously with &, the shell prints a line which looks like:
[1] 1234
indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process id was 1234.
This paragraph and the next require features that are not in all versions of UNIX and may not apply. If you are running a job and wish to do something else you may hit the key ^Z (control-Z) which sends a STOP signal to the current job. The shell will then normally indicate that the job has been `Stopped', and print another prompt. You can then manipulate the state of this job, putting it in the background with the bg command, or run some other commands and then eventually bring the job back into the foreground with the foreground command fg. A ^Z takes effect immediately and is like an interrupt in that pending output and unread input are discarded when it is typed.
A job being run in the background will stop if it tries to read from the terminal. Background jobs are normally allowed to produce output, but this can be disabled by giving the command stty tostop. If you set this tty option, then background jobs will stop when they try to produce output like they do when they try to read input.
There are several ways to refer to jobs in the shell. A job can be referred to by the process id of any process of the job or by one of the following:
The shell learns immediately whenever a process changes state. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only just before it prints a prompt. This is done so that it does not otherwise disturb your work. The notify option of the set command causes the shell to print these job change messages as soon as they occur.
When the monitor option is on, each background job that completes triggers any trap set for CHLD.
When you try to leave the shell while jobs are running or stopped, you will be warned that `You have stopped(running) jobs.' You may use the jobs command to see what they are. If you immediately try to exit again, the shell will not warn you a second time, and the stopped jobs will be terminated. When a login shell receives a HUP signal, it sends a HUP signal to each job that has not been disowned with the disown built-in command described below.
The shell variable
PATH
defines the search path for
the directory containing the command.
Alternative directory names are separated by
a colon
(:).
The default path is
/bin:/usr/bin:
(specifying
/bin,
/usr/bin,
and the current directory
in that order).
The current directory can be specified by
two or more adjacent colons, or by a colon
at the beginning or end of the path list.
If the command name contains a /, then the search path
is not used.
Otherwise, each directory in the path is
searched for an executable file
of the given name
that is not a directory.
If found, and if the shell
determines that there is a built-in version
of a command corresponding to a given pathname,
this built-in is invoked in the current process.
If found, and this directory is also contained in the value of the
FPATH
variable,
then this file is loaded into the current shell environment
as if it were the argument to the . command
except that only preset aliases are expanded,
and a function of the given name is executed
as described above.
If not found, and the file
.paths
is found, and this file contains a line of the form
FPATH=path
where
path
names an
existing directory, and this directory contains
a file of the given name,
then this file is loaded into the current shell environment
as if it were the argument to the . special built-in command
and a function of the given name is executed.
Otherwise, if found,
a process is created and
an attempt is made to execute the command via
When an executable is found, the directory where it is found in is searched for a file named .paths. If this file is found and it contains a line of the form BUILTIN_LIB=value , then the library named by value will be searched for as if it were an option argument to builtin -f, and if it contains a built-in of the specified name this will be executed instead of a command by this name. Otherwise, if this file is found and it contains a line of the form name =value in the first or second line, then the environment variable name is modified by prepending the directory specified by value to the directory list. If value is not an absolute directory, then it specifies a directory relative to the directory that the executable was found. If the environment variable name does not already exist it will be added to the environment list for the specified command.
If the file has execute permission but is not an a.out file, it is assumed to be a file containing shell commands. A separate shell is spawned to read it. All non-exported variables are removed in this case. If the shell command file doesn't have read permission, or if the setuid and/or setgid bits are set on the file, then the shell executes an agent whose job it is to set up the permissions and execute the shell with the shell command file passed down as an open file. A parenthesized command is executed in a sub-shell without removing non-exported variables.
The editing features require that the user's terminal accept `RETURN' as carriage return without line feed and that a space (` ') must overwrite the current character on the screen.
Unless the multiline option is on, the editing modes implement a concept where the user is looking through a window at the current line. The window width is the value of COLUMNS if it is defined, otherwise 80. If the window width is too small to display the prompt and leave at least 8 columns to enter input, the prompt is truncated from the left. If the line is longer than the window width minus two, a mark is displayed at the end of the window to notify the user. As the cursor moves and reaches the window boundaries the window will be centered about the cursor. The mark is a > (<, *) if the line extends on the right (left, both) side(s) of the window.
The search commands in each edit mode provide access to the history file. Only strings are matched, not patterns, although a leading ^ in the string restricts the match to begin at the first character in the line.
Each of the edit modes has an operation to list the files or commands that match a partially entered word. When applied to the first word on the line, or the first word after a ;, |, &, or (, and the word does not begin with ~ or contain a /, the list of aliases, functions, and executable commands defined by the PATH variable that could match the partial word is displayed. Otherwise, the list of files that match the given word is displayed. If the partially entered word does not contain any file expansion characters, a * is appended before generating these lists. After displaying the generated list, the input line is redrawn. These operations are called command name listing and file name listing, respectively. There are additional operations, referred to as command name completion and file name completion, which compute the list of matching commands or files, but instead of printing the list, replace the current word with a complete or partial match. For file name completion, if the match is unique, a / is appended if the file is a directory and a space is appended if the file is not a directory. Otherwise, the longest common prefix for all the matching files replaces the word. For command name completion, only the portion of the file names after the last / are used to find the longest command prefix. If only a single name matches this prefix, then the word is replaced with the command name followed by a space. When using a tab for completion that does not yield a unique match, a subsequent tab will provide a numbered list of matching alternatives. A specific selection can be made by entering the selection number followed by a tab.
The variable .sh.edcol is set to the input column number of the cursor at the time of the input. The variable .sh.edmode is set to ESC when in vi insert mode (see below) and is null otherwise. By prepending ${.sh.editmode} to a value assigned to .sh.edchar it will cause the shell to change to control mode if it is not already in this mode.
This trap is not invoked for characters entered as arguments to editing directives, or while reading input for a character search.
The notation for escape sequences is M- followed by a character. For example, M-f (pronounced Meta f) is entered by depressing ESC (ascii 033) followed by `f'. (M-F would be the notation for ESC followed by `SHIFT' (capital) `F'.)
All edit commands operate from any place on the line (not just at the beginning). Neither the `RETURN' nor the `LINE FEED' key is entered after edit commands except when noted.
When in vi mode on most systems, canonical processing is initially enabled and the command will be echoed again if the speed is 1200 baud or greater and it contains any control characters or less than one second has elapsed since the prompt was printed. The ESC character terminates canonical processing for the remainder of the command and the user can then modify the command line. This scheme has the advantages of canonical processing with the type-ahead echoing of raw mode.
If the option viraw is also set, the terminal will always have canonical processing disabled. This mode is implicit for systems that do not support two alternate end of line delimiters, and may be helpful for certain terminals.
Special built-ins cannot be bound to a pathname or deleted. The -d option deletes each of the given built-ins. On systems that support dynamic loading, the -f option names a shared library containing the code for built-ins. The shared library prefix and/or suffix, which depend on the system, can be omitted. Once a library is loaded, its symbols become available for subsequent invocations of builtin. Multiple libraries can be specified with separate invocations of the builtin command. Libraries are searched in the reverse order in which they are specified. When a library is loaded, it looks for a function in the library whose name is lib_init() and invokes this function with an argument of 0.
The second form of cd substitutes the string new for the string old in the current directory name, PWD, and tries to change to this new directory.
By default, symbolic link names are treated literally when finding the directory name. This is equivalent to the -L option. The -P option causes symbolic links to be resolved when determining the directory. The last instance of -L or -P on the command line determines which method is used.
The cd command may not be executed by rksh . rksh93 .
getopts places the next option letter it finds inside variable vname each time it is invoked. The option letter will be prepended with a + when arg begins with a +. The index of the next arg is stored in OPTIND. The option argument, if any, gets stored in OPTARG.
A leading : in optstring causes getopts to store the letter of an invalid option in OPTARG, and to set vname to ? for an unknown option and to : when a required option argument is missing. Otherwise, getopts prints an error message. The exit status is non-zero when there are no more options.
There is no way to specify any of the options :, +, -, ?, [, and ]. The option # can only be specified as the first option.
The exit status is 0 if the value of the last expression is non-zero, and 1 otherwise.
The -R option will print all subsequent arguments and options other than -n. The -e causes the above escape conventions to be applied. This is the default behavior. It reverses the effect of an earlier -r. The -p option causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. The -v option treats each arg as a variable name and writes the value in the printf %B format. The -C option treats each arg as a variable name and writes the value in the printf %#B format. The -s option causes the arguments to be written onto the history file instead of standard output. The -u option can be used to specify a one digit file descriptor unit number unit on which the output will be placed. The default is 1. If the option -n is used, no new-line is added to the output.
If no option name is supplied, then the current option settings are printed.
As an obsolete feature, if the first arg is - then the -x and -v options are turned off and the next arg is treated as the first argument. Using + rather than - causes these options to be turned off. These options can also be used upon invocation of the shell. The current set of options may be found in $-. Unless -A is specified, the remaining arguments are positional parameters and are assigned, in order, to $1 $2 . . . . If no arguments are given, then the names and values of all variables are printed on the standard output.
The -i attribute cannot be specified along with -R, -L, -Z, or -f.
Using + rather than - causes these options to be turned off. If no vname arguments are given, a list of vnames (and optionally the values ) of the variables is printed. (Using + rather than - keeps the values from being printed.) The -p option causes typeset followed by the option letters to be printed before each name rather than the names of the options. If any option other than -p is given, only those variables which have all of the given options are printed. Otherwise, the vnames and attributes of all variables that have attributes are printed.
If no option is given, -f is assumed.
The -v option produces a more verbose report. The -f option skips the search for functions. The -p option does a path search for name even if name is an alias, a function, or a reserved word. The -p option turns off the -v option. The -a option is similar to the -v option but causes all interpretations of the given name to be reported.
The remaining options and arguments are described under the set command above. An optional - as the first argument is ignored.
Unsetting the restricted option.
changing directory (see
cd(1)),
setting or unsetting the value or attributes of
SHELL,
ENV,
FPATH,
or
PATH,
specifying path or
command names containing
/,
redirecting output
(>,
>|,
<>,
and
>>).
adding or deleting built-in commands.
using
command -p
to invoke a command.
The restrictions above are enforced after .profile and the ENV files are interpreted.
When a command to be executed is found to be a shell procedure, rksh invokes ksh to execute it. Thus, it is possible to provide to the end-user shell procedures that have access to the full power of the standard shell, while imposing a limited menu of commands; this scheme assumes that the end-user does not have write and execute permissions in the same directory.
The net effect of these rules is that the writer of the .profile has complete control over user actions, by performing guaranteed setup actions and leaving the user in an appropriate directory (probably not the login directory).
The system administrator often sets up a directory of commands (e.g., /usr/rbin) that can be safely invoked by rksh.
$HOME/.profile
$HOME/..kshrc
/etc/suid_profile
/dev/null
Morris I. Bolsky and David G. Korn, The New KornShell Command and Programming Language, Prentice Hall, 1995.
POSIX - Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC 9945-2, IEEE, 1993.
If a command is executed, and then a command with the same name is installed in a directory in the search path before the directory where the original command was found, the shell will continue to exec the original command. Use the -t option of the alias command to correct this situation.
Some very old shell scripts contain a ^ as a synonym for the pipe character |.
Using the hist built-in command within a compound command will cause the whole command to disappear from the history file.
The built-in command . file reads the whole file before any commands are executed. Therefore, alias and unalias commands in the file will not apply to any commands defined in the file.
Traps are not processed while a job is waiting for a foreground process. Thus, a trap on CHLD won't be executed until the foreground job terminates.
It is a good idea to leave a space after the comma operator in arithmetic expressions to prevent the comma from being interpreted as the decimal point character in certain locales.
| RDS Standard | User Environment Utilities | July 01, 2009 |