Previous | Table of Contents | Next |
There are a number of variables provided by the Korn shell that allow you to customize your working environment. Some are automatically set by the Korn shell, some have a default value if not set, while others have no value unless specifically set.
Special Variables
CDPATH | search path for cd when not given a full pathname (no default) |
COLUMNS | window width for in-line edit mode and select command lists (default 80) |
EDITOR | pathname of the editor for in-line editing (default /bin/ed) |
ENV | pathname of the environment file (no default) |
ERRNO | error number returned by most recently failed system call (system dependent) |
FCEDIT | default editor for the fc command |
FPATH | search path for auto-loaded functions pathname of the history file |
HISTFILE | pathname of the history file (default $HOME/.sh_history) |
HISTSIZE | number of commands to save in the command history file (default 128) |
HOME | home directory |
IFS | internal field separator (default space, tab, newline) |
LINES | specifies column length for select lists |
name of mail file | |
MAILCHECK | specifies how often to check for mail (default 600 seconds) |
MAILPATH | search path for mail files (no default) |
OLDPWD | previous working directory |
OPTARG | value of the last getopts option argument |
OPTIND | index of the last getopts option argument |
PATH | search path for commands (default /bin:/usr/bin:) |
PPID | process id of the parent shell |
PS1 | primary prompt string (default $, #) |
PS2 | secondary prompt string (default >) |
PS3 | select command prompt (default #?) |
PS4 | debug prompt string (default +) |
RANDOM | contains a random number |
REPLY | contains the input to the read command when no variables are given |
SECONDS | contains number of seconds since Korn shell invocation |
SHELL | pathname of shell |
TERM | specifies your terminal type (no default) |
TMOUT | Korn shell timeout variable (default 0) |
VISUAL | pathname of the editor for in-line editing |
One-dimensional arrays are supported by the Korn shell. On most systems, arrays can have a maximum of 512 elements. Array subscripts start at 0 and go up to 511. Any variable can become an array by simply referring to it with a subscript.
Array Variable Assignment Format
variable[0]=value variable[1]=value ... variable[n]=value | |
set A variable value0 value1 ... valuen | |
typeset variable[0]=value variable[1]=value ... variable[n]=value | assign values to array variable elements |
set +A variable value0 value1 ... valuen | reassign values to array variable elements |
typeset attributes variable[0]=value variable[1]=value ... variable[n]=value | assign attributes and values to array variable elements |
typeset attributes variable | assign attributes to array variable |
typeset +attributes variable | remove attributes from array variable (except readonly) |
Array Variable Evaluation
${array}, $array | array element zero |
${array[n]} | array element n |
${array[*]}, ${array[@]} | all elements of an array |
${#array[*]}, ${#array[@]} | number of array elements |
${#array[n]} | length of array element n |
$(command) | replace with the standard output of command |
$((arithmetic-expression) | replace with the result of arithmetic-expression |
$(<file) | replace with the contents of file |
`command` | replace with the standard output of command (provided for compatibility with the Bourne shell) |
~ | replace with $HOME |
~user | replace with the home directory of user |
~ | replace with $OLDPWD (previous directory) |
~+ | replace with $PWD (current directory) |
Quotes are used when assigning values containing whitespace or special characters, to delimit variables, and to assign command output. They also improve readability by separating arguments from commands.
'...' | remove the special meaning of enclosed characters except ' |
"..." | remove the special meaning of enclosed characters except $, ', and \ |
\c | remove the special meaning of character c |
`command` | replace with the standard output of command (provided for compatibility with the Bourne shell) |
In-line editing provides the ability to edit the current or previous commands before executing them. There are three in-line editing modes available: emacs, gmacs, and vi. The emacs and gmacs modes are basically the same, except for the way Ctl-t is handled. The in-line editing mode is specified by setting the EDITOR or VISUAL variables, or with the set o command. The editing window width is specified by the COLUMNS variable. For lines longer than the window width, a mark is displayed to notify position. The marks >, <, and * specify that the line extends to the right, left, or both sides of the window.
Previous | Table of Contents | Next |