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 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. 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:
|
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. The predefined discipline functions are 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 in this table for an explanation of .sh.name, .sh.value, and .sh.subscript. Also available is .sh.version, which represents the version of the shell. |
Command Return Values |
Return values of commands 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. |
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 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 |
The enhanced Korn shell contains the following built-in commands:
|