Variable/Attribute Assignment Format
variable=
| declare variable and set it to null
|
typeset variable=
| declare variable and set it to null. If used within a function, then a local variable is declared.
|
variable=value
| assign value to variable
|
typeset variable=value
| assign value to variable. If used within a function, then a local variable is declared.
|
typeset attribute variable=value
| assign attribute and value to variable
|
typeset attribute variable
| assign attribute to variable
|
typeset +attribute variable
| remove attribute from variable (except readonly)
|
Variable/Attribute Listing Format
typeset attribute
| display a list of variable names and their values that have attribute set
|
typeset +attribute
| display a list of variable names that have attribute set
|
VARIABLE ATTRIBUTES
Variables can have one or more attributes that specify their internal representation, scope, or the way they are displayed.
Variable Attribute Assignment Format
typeset H variable
| Set UNIX to host-name file mapping for non-UNIX systems
|
typeset i variable
| Set variable to be integer type
|
typeset in variable
| Set variable to be integer type with base n
|
typeset l variable
| Set variable to lower case
|
typeset L variable
| Left justify variable; the field width is specified by the first assignment
|
typeset Ln variable
| Left justify variable; set field width to n
|
typeset LZn variable
| Left justify variable; set field width to n and strip leading zeros
|
typeset r variable
| Set variable to be readonly (same as readonly)
|
typeset R variable
| Right justify variable; the field width is specified by the first assignment
|
typeset Rn variable
| Right justify variable; set field width to n
|
typeset RZn variable
| Right justify variable; set field width to n and fill with leading zeros
|
typeset t variable
| Set the user-defined attribute for variable. This has no meaning to the Korn shell.
|
typeset u variable
| Set variable to upper case
|
typeset x variable
| Automatically export variable to the environment (same as export)
|
typeset Z variable
| Same as typeset RZ
|
VARIABLE SUBSTITUTION
Variable values can be accessed and manipulated using variable expansion. Basic expansion is done by preceding the variable name with the $ character. Other types of expansion can be used to return portions or the length of variables, use default or alternate values, assign default or alternate values, and more.
Variable Expansion Format
${variable}
| value of variable
|
${#variable}
| length of variable
|
${variable:word}
| value of variable if set and not null, else print word. If : is omitted, variable is only checked if it is set.
|
${variable:=word}
| value of variable if set and not null, else variable is set to word, then expanded. If : is omitted, variable is only checked if it is set.
|
${variable:?}
| value of variable if set and not null, else print "variable: parameter null or not set". If : is omitted, variable is only checked if it is set.
|
${variable:?word}
| value of variable if set and not null, else print value of word and exit. If : is omitted, variable is only checked if it is set.
|
${variable:+word}
| value of word if variable is set and not null, else nothing is substituted. If : is omitted, variable is only checked if it is set.
|
${variable#pattern}
| value of variable without the smallest beginning portion that matches pattern
|
${variable##pattern}
| value of variable without the largest beginning portion that matches pattern
|
${variable%pattern}
| value of variable without the smallest ending portion that matches pattern
|
${variable%%pattern}
| value of variable without the largest ending portion that matches pattern
|
SPECIAL PARAMETERS
Some special parameters are automatically set by the Korn shell, and usually cannot be directly set or modified.
Special Parameters
$#
| number of positional parameters
|
$@
| all positional parameters ("$1", "$2", ..., "$n")
|
$*
| all positional parameters ("$1 $2 ... $n")
|
$?
| exit status of the last command
|
$$
| process id of the current shell
|
$
| current options in effect
|
$!
| process id of the last background command or co-process
|
|