Bash Shell Options
A POSIX compliant shell can be configured with the set and unset builtins. To inspect the enabled options, use the $SHELLOPTS shell variable.
bash(1) expands on the set of configuration options. These options are set with the shopt builtins. To inspect the enabled options, use the $BASHOPTS shell variable.
Contents
Bash
Useful
If gnu_errfmt is enabled, error messages are written in the standard GNU format.
shopt -s gnu_errfmt shopt -u gnu_errfmt
If lastpipe is enabled,the last command of a pipeline is executing in the current shell as opposed to a subshell.
shopt -s lastpipe shopt -u lastpipe
Not Useful
If sourcepath is enabled, the source builtin searches $PATH for the sourced file.
shopt -s sourcepath shopt -u sourcepath
If checkhash is enabled, bash(1) checks for the existence of a command rather than assuming all commands in the hash table exist.
shopt -s checkhash shopt -u checkhash
login_shell and restricted_shell are set by bash(1) at startup, and cannot be changed. They simply allow inspection of the type of shell.
Changing Directories
If autocd is enabled, when command expansion fails, the shell instead moves to the named directory.
shopt -s autocd shopt -u autocd
If cdspell is enabled, simple spelling mistakes are automatically corrected. This includes transposed characters, one missing character, and one too many characters. To apply this functionality to all expansions, instead enable dirspell.
shopt -s cdspell shopt -u cdspell
If cdable_vars is enabled, trying to move into a directory that can't be found causes the name to instead be expanded as a variable.
shopt -s cdable_vars shopt -u cdable_vars
Comments
If interactive_comments is enabled, the comment character (#) works in interactive shells. This is enabled by default.
Compatibility Levels
bash(1) 4 introduced compatibility levels, wherein the behavior of the shell are modified.
shopt -s compat31 shopt -u compat31
The modes available through the shopt builtin are:
compat31
compat32
compat40
compat41
compat42
compat43
compat44
A shell only has one compatibility level, so each mode is mutually exclusive.
From bash(1) 4.3+, use of the $BASH_COMPAT shell variable is preferred.
Completion
If progcomp is enabled, programmable completion is used. This is enabled by default.
If progcomp_alias is enabled, when completion fails for a word, the word is checked for an alias. If an alias is registered, completion is re-attempted based on the aliased value.
If force_fignore is enabled and the $FIGNORE shell variable is set, the filtered filenames will be ignored by completion even if they are the only possible expansions. This is enabled by default.
If hostcomplete is enabled, hostname completion will be tried for any word containing @. This is enabled by default.
If direxpand is enabled, when filenames are expanded to an absolute path, the expansion is substituted into the command line.
shopt -s direxpand shopt -u direxpand
Expansion
If expand_aliases is enabled, aliases are expanded. By default, this is enabled for interactive shells.
If globasciiranges is enabled, bracketed range expressions behave as though the C locale is set. In other words, [A-z] would be a portable way to express any letter.
shopt -s globasciiranges shopt -u globasciiranges
If dotglob is enabled, filenames beginning with . are included in filename expansions.
shopt -s dotglob shopt -u dotglob
If globstar is enabled, the pattern ** matches all files and subdirectories with zero or more directories in the path. Additionally, **/ will only match subdirectories with zero or more directories in the path.
shopt -s globstar shopt -u globstar
If nocaseglob is enabled, filename expasion operates case-insensitively. To apply this functionality to the regular expression match operator as well, instead enable nocasematch.
shopt -s nocaseglob shopt -u nocaseglob
If failglob is enabled, a filename pattern that does not expand to any filenames results in an error.
shopt -s failglob shopt -u failglob
If nullglob is enabled, a filename pattern that does not expand to any filenames expands to a null string.
shopt -s nullglob shopt -u nullglob
If dirspell is enabled, simple spelling mistakes are automatically corrected in filename expansion. This includes transposed characters, one missing character, and one too many characters. To apply this functionality only to the cd builtin, instead enable cdspell.
shopt -s dirspell shopt -u dirspell
If no_empty_cmd_completion is enabled, when the command prompt is empty, no completion is attempted.
shopt -s no_empty_cmd_completion shopt -u no_empty_cmd_completion
If extglob is enabled, extended pattern matching features become available.
shopt -s extglob shopt -u extglob
If assoc_expand_once is enabled, associative array subscripts have expansion postponed.
shopt -s assoc_expand_once shopt -u assoc_expand_once
Extended Debugging Mode
If extdebug is enabled, tracing begins.
shopt -s extdebug shopt -u extdebug
History
If history is enabled, the history of commands is available for editting and re-execution. This behavior is configured with a set of shell variables.
If cmdhist is enabled and command history is enabled, multi-line commands are collapsed to a single line when saving into history. This is enabled by default.
If lithist is enabled as well as cmdhist, multi-line commands are recorded in history with embedded newlines rather than semicolons.
shopt -s lithist shopt -u lithist
If histappend is set, the history file is appended to rather than overwritten when the shell exits.
shopt -s histappend shopt -u histappend
If histreedit is set and readline(3) is available, history can be re-editted.
shopt -s histreedit shopt -u histreedit
If histverify is set, when a command is expanded with history substitution, the prompt reloads with the updated content (as opposed to the shell executing the updated command immediately).
shopt -s histverify shopt -u histverify
Interactive Shells
If checkjobs is enabled, before an interactive shell is exitted, all stopped and running jobs will be listed. If there are any, the exit is postponed until another exit is attempted.
shopt -s checkjobs shopt -u checkjobs
If huponexit is enabled, SIGHUP is sent to all jobs on exit.
shopt -s huponexit shopt -u huponexit
If mailwarn is enabled, when a watched mail file has been accessed, a notification message is printed.
shopt -s mailwarn shopt -u mailwarn
Programming
If shift_verbose is enabled, when the shift builtin is used exceeding the number of positional variables, an error message is emitted.
shopt -s shift_verbose shopt -u shift_verbose
If nocasematch is enabled, the regular expression matching operator works case-insensitively. This also impacts expansion. To apply this functionality only to expansion, instead enable nocaseglob.
shopt -s nocasematch shopt -u nocasematch
If execfail is enabled, when the exec builtin fails because the command could not be located, the non-interactive shell does not exit.
shopt -s execfail shopt -u execfail
If xpg_echo is enabled, the echo builtin expands ANSI sequences by default.
shopt -s xpg_echo shopt -u xpg_echo
Prompts
If promptvars is enabled, prompt strings undergo expansion after sequences are expanded. This is enabled by default.
Quoting
If extquote is enabled, ANSI quoting and local translation quoting are performed within parameter expansion. This is enabled by default.
If complete_fullquote is enabled, filenames containing special characters are quoted during filename expansion. This is enabled by default.
Subshell Inheritence
If inherit_errexit is enabled, the errexit setting propogates into subshells (chiefly in command substitutions).
shopt -s inherit_errexit shopt -u inherit_errexit
If localvar_inherit is enabled, local variables are exported into subshells.
shopt -s localvar_inherit shopt -u localvar_inherit
If localvar_unset is enabled, unsetting a local variable causes it to appear unset to subshells as well.
shopt -s localvar_unset shopt -u localvar_unset
Window Size
If checkwinsize is enabled, bash(1) checks the window size after every (non-builtin) command. This triggers updates to the $LINES and $COLUMNS shell variables. By default, this is enabled for interactive shells.