Setting Korn Shell Options

Options are switches that control the behavior of the Korn shell. Options are boolean, meaning that they can be either on or off.

To switch an option on, type:

$ set -o option_name

To switch an option off, type:

$ set +o option_name

To show current option settings, type:

$ set -o
Note: The set -o and set +o options can only change a single option setting at a time.

Protecting File Content During I/O Redirection

Redirecting standard output to an existing file overwrites the previous file content, which results in data loss. This process of overwriting existing data is known as clobbering. To prevent an overwrite from occurring, the shell supports a noclobber option.

When the noclobber option is set, the shell refuses to redirect standard output to the existing file and displays an error message to the screen.

The noclobber option is activated in the shell using the set command. For example:

$ set -o noclobber
$ set -o | grep noclobber
noclobber        on
$ ps -ef > file_new
$ cat /etc/passwd > file_new
ksh: file_new: file already exists

Deactivating the noclobber Option

To temporarily deactivate the noclobber option, use the >| deactivation syntax on the command line. The noclobber option is ignored for this command line only, and the contents of the file are overwritten.

$ ls -l >| file_new

Note: There is no space between the > and | on the command line.

To deactivate the noclobber option, perform the following commands:

$ set +o noclobber $ set -o | grep noclobber
noclobber off
$ ls -l > file_new $

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.