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


Book HomeBook TitleSearch this book

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 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 whitespace. 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
bgnice

Run background jobs at lower priority (on by default).

emacs

Enter emacs editing mode.

ignoreeof

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

markdirs

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

noclobber

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

noglob

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

nounset

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

trackall

Turn on alias tracking. (The shell actually ignores the setting of this option; alias tracking is always turned on. This is discussed in Section 3.4.2.8, later in this chapter.)

vi

Enter vi editing mode.

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 prints a list of all options along with their settings. There is no command for testing single options, but here is a simple shell function to do it:

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

    else
        print Option $1 is off.
    fi
}

Shell functions are 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 Section 3.5.2, later in this chapter), type either login or . .profile. (Yes, the period, or "dot," is actually a command; see Section 4.1 in Chapter 4.) Then you can type testopt optionname to check the status of an option.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.