预计阅读本页时间:-
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 optionname and set +o optionname. You can change more than one option with the one set command by preceding each optionname with a -o or +o. 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.
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
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 carryovers from the Bourne shell. Like several other "extra" bash 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
emacs
Enters emacs editing mode (on by default)
ignoreeof
Doesn't allow use of a single CTRL-D to log off; use the exit command to log off immediately (this has the same effect as setting the shell variable IGNOREEOF=10)
noclobber
Doesn't allow output redirection (>) to overwrite an existing file
noglob
Doesn't expand filename wildcards like * and ? (wildcard expansion is sometimes called globbing)
nounset
Indicates an error when trying to use a variable that is undefined
vi
Enters vi editing mode
There are several other options (21 in all; Appendix B lists them). To check the status of an option, just type set -o. bash will print a list of all options along with their settings.