Home

shopt

Shopt is a builtin command in the Bash shell that controls the behavior of the shell by enabling or disabling certain boolean options. These options affect features such as filename expansion (globbing), pattern matching, and how history and input are handled. Shopt options are specific to Bash and may not exist in other shells.

Usage and basic behavior: shopt [-pqsu] [optname ...]. If optname is omitted, shopt shows the status of

Commonly used options include:

- extglob: enables extended pattern matching for complex glob patterns.

- nullglob: patterns that do not match expand to nothing instead of themselves.

- failglob: patterns that do not match cause an error.

- dotglob: include files beginning with a dot in glob results.

- globstar: enables recursive globbing with **.

- nocasematch: makes pattern matching case-insensitive.

- autocd: allows changing directories by typing a directory name alone.

- cdspell: corrects minor typos in directory names during cd.

- histappend: appends history lines to the history file instead of overwriting it.

- checkwinsize: updates the shell’s idea of window size after each command.

Examples:

- shopt -s extglob

- shopt -s nullglob

- shopt -p extglob

- if shopt -q nocasematch; then echo on; fi

Notes: The set of available options varies with Bash version, and some options may be unsupported

all
supported
options.
The
-s
flag
enables
one
or
more
options,
-u
disables
them,
and
the
-p
prints
each
option
in
a
form
that
can
be
reused.
The
-q
flag
suppresses
normal
output,
returning
an
exit
status
instead.
The
exact
options
available
depend
on
the
Bash
version
in
use.
in
other
shells.
Shopt
complements
set
-o
by
targeting
a
curated
list
of
features
related
to
globbing,
history,
and
interactive
shell
behavior.