9.12. Bash Options

9.12.1. Shell Invocation Options

When the shell is started using the bash command, it can take options to modify its behavior. There are two types of options: single-character options and multicharacter options. The single-character options consist of a single leading dash followed by a single character. The multicharacter options consist of two leading dashes and any number of characters. Multicharacter options must appear before single-character options. An interactive login shell normally starts up with -i (start an interactive shell), -s (read from standard input), and -m (enable job control). See Table 9.8 on page 475.

Table 9.8. Bash 2.x Shell Invocation Options
OptionMeaning
-c stringCommands are read from string. Any arguments after string are assigned to positional parameters, starting at $0.
-DA list of double quoted strings, preceded by a $, are printed to standard output. These strings are subject to language translation when the current locale is not C or POSIX. The -n option is implied; no commands will be executed.
-iShell is in the interactive mode. TERM, QUIT, and INTERRUPT are ignored.
-sCommands are read from standard input and allow the setting of positional parameters.
-rStarts a restricted shell.
--Signals the end of options and disables further option processing. Any arguments after -- or - are treated as filenames and arguments.
--dump-stringsSame as -D.
--helpDisplays a usage message for a built-in command and exits.
--loginCauses bash to be invoked as a login shell.
--noeditingWhen bash is running interactively, does not use the Readline library.
--noprofileWhen starting up, bash does not read the initialization files: /etc/profile, ~/.bash_profile, ~/.bash_login, or ~/.profile.
--norcFor interactive shells, bash will not read the ~/.bashrc file. Turned on by default, if running shell as sh.
--posixChanges the behavior of bash to match the POSIX 1003.2 standard, if otherwise it wouldn't.
--quietDisplays no information at shell startup, the default.
--rcfile fileIf bash is interactive, uses this intialization file instead of ~/.bashrc.
--restrictedStarts a restricted shell.
--verboseTurns on verbose; same as -v.
--versionDisplays version information about this bash shell and exit.

Table 9.9. Bash (Versions Prior to 2.x) Shell Invocation Options
-c stringCommands are read from string. Any arguments after string are assigned to positional parameters, starting at $0.
-DA list of double quoted strings, preceded by a $, are printed to standard output. These strings are subject to language translation when the current locale is not C or POSIX. The -n option is implied; no commands will be executed.
-iShell is in the interactive mode. TERM, QUIT, and INTERRUPT are ignored.
-sCommands are read from standard input and allows the setting of positional parameters.
-rStarts a restricted shell.
-Signals the end of options and disables further option processing. Any arguments after -- or - are treated as filenames and arguments.
-loginCauses bash to be invoked as a login shell.
-nobraceexpansionCurly brace expansion is turned off.
-nolineeditingWhen bash is running interactively, does not use the Readline library.
-noprofileWhen starting up, bash does not read the initialization files: /etc/profile, ~/.bash_profile, ~/.bash_login, or ~/.profile.
-posixChanges the behavior of bash to match the POSIX standard, if otherwise, it wouldn't.
-quietDisplays no information at shell startup, the default.
-rcfile fileIf bash is interactive, uses this intialization file instead of ~/.bashrc.
-verboseTurns on verbose; same as -v.
-versionDisplays version information about this bash shell and exit.

9.12.2. The set Command and Options

The set command can be used to turn shell options on and off, as well as for handling command line arguments. To turn an option on, the dash (-) is prepended to the option; to turn an option off, the plus sign (+) is prepended to the option. See Table 9.10 on page 477 for a list of set options.

Example 9.78.
1 $ set -f

2 $ echo **

3 $ echo ??
  ??

4 $ set +f

Explanation

  1. The f option is turned on, disabling filename expansion.

  2. The asterisk is not expanded.

  3. The question marks are not expanded.

  4. The f is turned off; filename expansion is enabled.

Table 9.10. The Built-In set Command Options
Name of OptionShortcut SwitchWhat It Does
allexport-aAutomatically marks new or modified variables for export from the time the option is set, until unset.
[1]braceexpand-BEnables brace expansion, and is a default setting.
emacs For command line editing, uses the emacs built-in editor, and is a default setting
errexit-eIf a command returns a nonzero exit status (fails), exits. Not set when reading initialization files.
[a]histexpand-HEnables ! and !! when performing history substitution, and is a default setting.
[a]history Enables command line history; on by default.
ignoreeof Disables EOF (Control-D) from exiting a shell; must type exit. Same as setting shell variable, IGNOREEOF=10.
[a]keyword-kPlaces keyword arguments in the environment for a command.
interactive-comments For interactive shells, a leading # is used to comment out any text remaining on the line.
monitor-mAllows job control.
noclobber-CProtects files from being overwritten when redirection is used.
noexec-nReads commands, but does not execute them. Used to check the syntax of scripts. Not on when running interactively.
noglob-dDisables pathname expansion; i.e., turns off wildcards.
notify-bNotifies user when background job finishes
nounset-uDisplays an error when expanding a variable that has not been set.
[a]onecmd-tExits after reading and executing one command.
physical-PIf set, does not follow symbolic links when typing cd or pwd. The physical directory is used instead.
posix Shell behavior is changed if the default operation doesn't match the POSIX standard.
privileged-pWhen set, the shell does not read the .profile or ENV file and shell functions are not inherited from the environment; automatically set for setuid scripts.
posix Changes the default behavior to POSIX 1003.2
verbose-vTurns on the verbose mode for debugging.
vi For command line editing, uses the vi built-in editor.
xtrace-xTurns on the echo mode for debugging.

[1] Asterisk indicates option applies only to versions of bash 2.x.

9.12.3. The shopt Command and Options

The shopt (bash 2.x) command can also be used to turn shell options on and off.

Table 9.11. The shopt Command Options
OptionMeaning
cdable_varsIf an argument to the cd built-in command is not a directory, it is assumed to be the name of a variable whose value is the directory to change to.
cdspellCorrects minor errors in the spelling of a directory name in a cd command. The errors checked for are transposed characters, a missing character, and a character too many. If a correction is found, the corrected path is printed, and the command proceeds. Only used by interactive shells.
checkhashBash checks that a command found in the hash table exists before trying to execute it. If a hashed command no longer exists, a normal path search is performed.
checkwinsizeBash checks the window size after each command and, if necessary, updates the values of LINES and COLUMNS.
cmdhistBash attempts to save all lines of a multiple-line command in the same history entry. This allows easy re-editing of multiline commands.
dotglobBash includes filenames beginning with a "." in the results of filename expansion.
execfailA noninteractive shell will not exit if it cannot execute the file specified as an argument to the exec built-in command. An interactive shell does not exit if exec fails.
expand_aliasesAliases are expanded. Enabled by default.
extglobThe extended pattern matching features (regular expression metacharacters derived from Korn shell for filename expansion) are enabled.
histappendThe history list is appended to the file named by the value of the HISTFILE variable when the shell exits, rather than overwriting the file.
histreeditIf Readline is being used, a user is given the opportunity to re-edit a failed history substitution.
histverifyIf set, and Readline is being used, the results of history substitution are not immediately passed to the shell parser. Instead, the resulting line is loaded into the Readline editing buffer, allowing further modification.
hostcompleteIf set, and Readline is being used, bash will attempt to perform hostname completion when a word containing an "@" is being completed Enabled by default.
huponexitIf set, bash will send SIGHUP (hangup signal) to all jobs when an interactive login shell exits.
interactive_comments Allows a word beginning with "#" to cause that word and all remaining characters on that line to be ignored in an interactive shell. Enabled by default.
lithistIf enabled, and the cmdhist option is enabled, multiline commands are saved to the history with embedded newlines rather than using semicolon separatorswhere possible.
mailwarn If set, and a file that bash is checking for mail has been accessed since the last time it was checked, the message The mail in mailfile has been read is displayed.
nocaseglobIf set, bash matches filenames in a case-insensitive fashion when performing filename expansion.
nullglobIf set, bash allows filename patterns which match no files to expand to a null string, rather than themselves.
promptvars If set, prompt strings undergo variable and parameter expansion after being expanded. Enabled by default.
restricted_shell The shell sets this option if it is started in restricted mode. The value may not be changed. This is not reset when the startup files are executed, allowing the startup files to discover whether or not a shell is restricted.
shift_verboseIf this is set, the shift built-in prints an error message when the shift count exceeds the number of positional parameters.
sourcepathIf set, the source built-in uses the value of PATH to find the directory containing the file supplied as an argument. Enabled by default.
sourceA synonym for . (a dot)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.206.254