Previous Table of Contents Next


Reviewing Korn Shell Initialization Files

The Korn shell uses two initialization files in the user's home directory to set the user's environment: .profile and .ksh-env, which is a file with any name you choose that controls the user's environment. You might want to name the file .kshrc, because its function is similar to the C shell .cshrc file.

When the user logs in, the .profile file is read and then the .ksh-env file. The .ksh-env file lets you configure the Korn shell session to your needs. Many of the commands that you would include in the .ksh-env file can be executed only by the Korn shell and cannot be included in the .profile file.

You must set the ENV environment variable to point to the .ksh-env file. The syntax for setting environment variables in the Korn shell is the same as for the Bourne shell: VARIABLE=value;export VARIABLE. As in the Bourne shell, you must export the variable to make it available to the shell. This example sets the environment variable for a .kshrc file:

$ ENV=$HOME/.kshrc;export ENV
$

You set this environment variable in the .profile file; otherwise, the .kshrc file will not be found when the user logs in. The ENV variable has no default setting. Unless you set it, the feature is not used. The .ksh-env file is read each time a user starts the Korn shell from a command line.

Using Korn Shell Options

The Korn shell has a number of options that specify the user's environment and control execution of commands. To display the current option settings, type set -o and press Return. In this example, the default options for the Korn shell for Solaris 2.x system software are displayed:

$ set -o
Current option settings
allexport        off
bgnice           on
emacs            off
errexit          off
gmacs            off
ignoreeof        off
interactive      on
keyword          off
markdirs         off
monitor          on
noexec           off
noclobber        off
noglob           off
nolog            off
nounset          off
privileged       off
restricted       off
trackall         off
verbose          off
vi               off
viraw            off
xtrace           off
$

The default options are described in Table 8-2. Customarily, these options are set in the .ksh-env file.

Table 8-2 Korn Shell Options

Option Default Description
allexport off Automatically exports variables when defined.
bgnice on Executes all background jobs at a lower priority.
emacs off Sets emacs/gmacs as the in-line editor.
errexit off If a command returns the value False, the shell executes the ERR trap (if set), and immediately exits.
gmacs off Sets gmacs as the in-line editor.
ignoreeof off When the interactive option is also set, the shell does not exit at end-of-file. Type exit to quit the shell.
interactive on The shell automatically turns the interactive option on so that shell prompts are displayed.
keyword off The shell puts each word with the syntax of a variable assignment in the variable assignment list.
markdirs off Displays a / following the names Kof all directories resulting from path name expansion.
monitor on Enables job control.
noclobber off Does not overwrite an existing file when the redirect operator (>) is used.
noexec off Reads commands but does not execute them. You can use this option to debug shell script syntax errors.
noglob off Disables file name expansion.
nolog off Does not store function definitions in the history file.
nounset off Displays an error message when the shell tries to expand a variable that is not set.
privileged off When this option is off, the real UID and GID are used. When this option is on, the UID and GID are set to the values that were in effect when you started the shell.
restricted off Sets a restricted shell.
trackall off Makes command-tracked aliases when they are first encountered.
verbose off Displays the input as it is read.
vi off Sets vi as the in-line editor.
viraw off Specifies character-at-a-time input from vi.
xtrace off Displays commands and arguments as they are executed.

To enable an option, type set -o option-name and press Return. To disable an option, type set +o option-name and press Return.

For example, entering this line in the user's .ksh-env file will set the in-line editor to vi:

set -o vi

This turns off vi as the in-line editor:

set +o vi

You can also set these options from a command line using the same syntax.


Previous Table of Contents Next