In addition to the default system Korn shell (/usr/bin/ksh), AIX provides an enhanced version available as /usr/bin/ksh93. This enhanced version is upwardly compatible with the current default version, and includes a few additional features that are not available in /usr/bin/ksh. The following table contains an overview of these additional features.
The following features are available in /usr/bin/ksh93:
Arithmetic Enhancements |
You can use libm functions (math functions typically found in the C
programming language), within arithmetic expressions, such as $
value=$((sqrt(9))). More arithmetic operators are available,
including the unary +, ++, --, and the
?: construct (for example, "x ? y : z"), as
well as the , (comma) operator. Arithmetic bases are
supported up to base 64. Floating point arithmetic is also
supported. "typeset -E" (exponential) can be used to specify
the number of significant digits and "typeset -F" (float) can be
used to specify the number of decimal places for an arithmetic
variable. The SECONDS variable now displays to the nearest
hundredth of a second, rather than to the nearest second.
|
Compound Variables |
Compound variables are supported in ksh93. A compound variable allows a user to specify multiple values within a single variable name. The values are each assigned with a subscript variable, separated from the parent variable with a . (period). For example:
$ myvar=( x=1 y=2 ) $ print "${myvar.x}" 1 |
Compound Assignments |
Compound assignments are supported when initializing arrays, both for indexed arrays and associative arrays. The assignment values are placed in parentheses as shown in the following example:
$ numbers=( zero one two three ) $ print ${numbers[0]} ${numbers[3]} zero three |
Associative Arrays | An associative array is an array with a string as an index.
The typeset command used with the -A flag allows you to specify associative arrays within ksh93. For example:
$ typeset -A teammates $ teammates=( [john]=smith [mary]=jones ) $ print ${teammates[mary]} jones |
Variable Name References |
The typeset command used with the -n flag allows you to assign one variable name as a reference to another. In this way, modifying the value of a variable will in turn modify the value of the variable that is referenced. For example:
$ greeting="hello" $ typeset -n welcome=greeting # establishes the reference $ welcome="hi there" # overrides previous value $ print $greeting hi there |
Parameter Expansions |
The following parameter-expansion constructs are available in ksh93:
|
Discipline Functions |
A discipline function is a function that is associated with a specific variable. This allows you to define and call a function every time that variable is referenced, set, or unset. These functions take the form of varname.function, where varname is the name of the variable and function is the discipline function. There are three predefined discipline functions: get, set, and unset.
Within all discipline functions, the special variable .sh.name is set to the name of the variable, while .sh.subscript is set to the value of the variables subscript, if applicable. |
Function Environments |
Functions declared with the function myfunc format
are executed in a separate function environment. Functions declared as
myfunc() execute with the same environment as the parent
shell.
|
Variables |
Variables beginning with .sh. are reserved by the shell and have special meaning. See the description of Discipline Functions above for an explanation of .sh.name, .sh.value, and .sh.subscript. Also available is .sh.version, which represents the version of the shell. Note: The variable ERRNO is no longer
available.
|
Command Return Values |
Return values of commands in ksh93 are as follows:
|
PATH Search Rules |
Special built-in commands are searched for first, followed by all functions
(including those in FPATH directories), followed by other built-ins.
Previously, all built-ins were searched before all functions, and FPATH
functions were not searched until after everything in PATH.
|
Shell History |
The hist command allows you to display and edit the shells
command history. In the ksh shell, the fc command was
used. The fc command is now an alias to
hist. Variables are HISTCMD, which increments once for each
command executed in the shells current history, and HISTEDIT, which specifies
which editor to use when using the hist command.
|
Built-In Commands |
|