The Korn Shell, or POSIX shell, enables you to do parameter substitutions.
This section discusses the following:
A parameter is defined as the following:
The typeset special built-in command assigns values and attributes to named parameters. The attributes supported by the Korn shell are described with the typeset special built-in command. Exported parameters pass values and attributes to the environment.
The value of a named parameter is assigned by:
Name=Value [ Name=Value ] ...
If the -i integer attribute is set for the Name parameter, the Value parameter is subject to arithmetic evaluation. Refer to Arithmetic Evaluation in the Korn Shell or POSIX Shell for more information about arithmetic expression evaluation.
The shell supports a one-dimensional array facility. An element of an array parameter is referenced by a subscript. A subscript is denoted by an arithmetic expression enclosed by brackets ([ ]). To assign values to an array, use set -A Name Value ... . The value of all subscripts must be in the range of 0 through 511. Arrays need not be declared. Any reference to a named parameter with a valid subscript is legal and an array will be created, if necessary. Referencing an array without a subscript is equivalent to referencing the element 0.
Positional parameters are assigned values with the set special command. The $0 parameter is set from argument 0 when the shell is invoked. The $ character is used to introduce parameters that can be substituted.
The following are substitutable parameters:
Note: If the : is omitted from the previous expressions, the shell checks only whether the Parameter parameter is set.
The following parameters are automatically set by the shell:
@ | Expands the positional parameters, beginning with $1. Each parameter is separated by a space.
If you place " around $@, the shell considers each positional parameter a separate string. If no positional parameters exist, the shell expands the statement to an unquoted null string. |
* | Expands the positional parameters, beginning with $1. The shell separates each parameter with the first character of the
IFS parameter value.
If you place " around $*, the shell includes the positional parameter values in double quotation marks. Each value is separated by the first character of the IFS parameter. |
# | Specifies the number (in decimals) of positional parameters passed to the shell, not counting the name of the shell procedure itself. The $# parameter thus yields the number of the highest-numbered positional parameter that is set. One of the primary uses of this parameter is to check for the presence of the required number of arguments. |
- | Supplies flags to the shell on invocation or with the set command. |
? | Specifies the exit value of the last command executed. Its value is a decimal string. Most commands return 0 to indicate successful completion. The shell itself returns the current value of the $? parameter as its exit value. |
$ | Identifies the process number of this shell. Because process numbers
are unique among all existing processes, this string of up to 5 digits is
often used to generate unique names for temporary files.
The following example illustrates the recommended practice of creating temporary files in a directory used only for that purpose: temp=$HOME/temp/$$ ls >$temp . . . rm $temp |
! | Specifies the process number of the most recent background command invoked. |
zero (0) | Expands to the name of the shell or shell script. |
The following variables are set by the shell:
The following variables are used by the shell:
The shell gives default values to the PATH, PS1, PS2, MAILCHECK, TMOUT, and IFS parameters, but the HOME, SHELL, ENV, and MAIL parameters are not set by the shell (although the HOME parameter is set by the login command).