4.3 VariablesThis section describes the following:
4.3.1 Variable Substitutionksh93
provides structured variables, such as
No spaces should be used in the following expressions. The colon (
In the Korn shell:
In ksh93 :
In ksh93
, indirect variables allow you to "alias" one variable name to affect the value of another. This is accomplished using $ 4.3.1.1 Examples$ 4.3.1.2 Korn shell exampletail='${PWD##*/}' Take the current directory name and remove the longest character string ending with /, which removes the leading pathname and leaves the tail 4.3.2 Built-in Shell Variables
Built-in variables are automatically set by the shell and are typically used inside shell scripts. Built-in variables can make use of the variable substitution patterns shown previously. Note that the
The Korn shell automatically sets these additional variables: ksh93
automatically sets these additional variables. Variables whose names contain "." must be enclosed in braces when referenced, e.g.,
4.3.3 Other Shell VariablesThe following variables are not automatically set by the shell. They are typically used in your .profile file, where you can define them to suit your needs. Variables can be assigned values by issuing commands of the form: variable =value This list includes the type of value expected when defining these variables. Those that are specific to the Korn shell are marked as (K). Those that are specific to ksh93 are marked (K93). 4.3.4 ArraysThe Korn shell supports one-dimensional arrays of up to 1024 elements. The first element is numbered 0. An array name can be initialized as follows: set -A name value0 value1 ... where the specified values become elements of name . Declaring arrays is not required, however. Any valid reference to a subscripted variable can create an array.
When referencing arrays, use the
ksh93
provides associative arrays, where the indices are strings instead of numbers (as in awk
). In this case, data=([joe]=30 [mary]=25) The values would be retrieved as 4.3.5 Discipline Functions (ksh93 only)
Along with structured variables, ksh93
introduces discipline functions
. These are special functions that are called whenever a variable's value is accessed or changed. For a shell variable named
Within the discipline functions, special variables provide information about the variable being changed:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|