home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Learning the Korn Shell

Learning the Korn ShellSearch this book
Previous: 3.2 Aliases Chapter 3
Customizing Your Environment
Next: 3.4 Shell Variables

3.3 Options

While aliases let you create convenient names for commands, they don't really let you change the shell's behavior. Options are one way of doing this. A shell option is a setting that is either "on" or "off." While several options relate to arcane shell features that are of interest only to programmers, those that we will cover here are of interest to all users.

The basic commands that relate to options are set -o optionnames and set +o optionnames , where optionnames is a list of option names separated by blanks. The use of plus (+ ) and minus (- ) signs is counterintuitive: the - turns the named option on, while the + turns it off. The reason for this incongruity is that the dash (- ) is the conventional UNIX way of specifying options to a command, while the use of + is an afterthought.

Most options also have one-letter abbreviations that can be used in lieu of the set -o command; for example, set -o noglob can be abbreviated set -f . These abbreviations are carry-overs from the Bourne shell. Like several other "extra" Korn shell features, they exist to ensure upward compatibility; otherwise, their use is not encouraged.

Table 3.1 lists the options that are useful to general UNIX users. All of them are off by default except as noted.

Table 3.1: Basic Shell Options
Option Description

Run background jobs at lower priority (on by default)


Enter emacs editing mode


Don't allow use of [CTRL-D] to log off; require the exit command


When expanding filename wildcards, append a slash (/ ) to directories


Don't allow output redirection (> ) to clobber an existing file


Don't expand filename wildcards like * and ? (wildcard expansion is sometimes called globbing )


Indicate an error when trying to use a variable that is undefined


Turn on alias tracking[6]


Enter vi editing mode

[6] Future releases will have alias tracking enabled at all times and won't support this option.

There are several other options (22 in all; Appendix B lists them). To check the status of an option, just type set -o . The Korn shell will print a list of all options along with their settings. There is no direct way to test a single option, but here is a simple shell function to do it:

function testopt {
    if [[ -o $1 ]] ; then
        print Option $1 is on.
        print Option $1 is off.

Shell functions will be covered in the next chapter. For now, though, if you want to use the testopt function, just type it into your .profile or environment file (see the section entitled "The Environment File"), then type either login or . .profile . Then you can type testopt optionname to check the status of an option.

Previous: 3.2 Aliases Learning the Korn Shell Next: 3.4 Shell Variables
3.2 Aliases Book Index 3.4 Shell Variables

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System