3.3. OptionsWhile 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
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. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|