shopt
Set or display shell options
TLDR
List of all settable options and whether they are set
Set an option
Unset an option
Print a list of all options and their status formatted as runnable shopt commands
Display help
SYNOPSIS
shopt [-pqsu] [-o] [optname ...]
PARAMETERS
-p
Print shell options in a format that can be reused as input for shopt.
-q
Suppress output; primarily used for testing if an option is set or unset by checking the exit status.
-s
Set (enable) the specified shell options.
-u
Unset (disable) the specified shell options.
-o
Restrict options to those from set -o that are also controllable by shopt.
optname
The name of the shell option to act upon. If omitted with -s or -u, shopt lists all current option settings.
DESCRIPTION
shopt is a Bash built-in command used to examine, set, or unset a variety of shell options that control the shell's behavior. These options are distinct from those managed by set -o, offering finer-grained control over various aspects of interactive and non-interactive Bash sessions. It enables users to customize features like history expansion, filename globbing, command completion, and more.
When invoked without arguments, shopt lists all available options and their current status (on/off). By specifying optname with -s or -u, users can enable or disable specific behaviors. This command is crucial for tailoring the Bash environment to individual preferences or script requirements.
CAVEATS
shopt is a Bash-specific built-in command and is not available in other shells like zsh, dash, or ksh (which have their own mechanisms for option management).
Options set with shopt are typically local to the current shell session or script where they are applied. They do not persist across new shell invocations unless set in a shell startup file (e.g., ~/.bashrc).
LISTING OPTIONS
To see all currently configured shopt options and their status (on/off), simply run shopt without any arguments. Use shopt -s to list only enabled options, and shopt -u to list only disabled options.
COMMON USE CASES
Commonly used for enabling or disabling features like cdspell (corrects minor spelling errors in cd arguments), extglob (enables extended pattern matching for globbing), histappend (appends history to the history file rather than overwriting), and autocd (allows typing a directory name to change to it).
HISTORY
The shopt command was introduced in later versions of Bash to provide a more granular and extensive set of options compared to the traditional set -o command. Its development aimed to offer finer control over specific Bash behaviors, enabling users to customize their interactive shell experience and write more robust scripts. It became a standard part of Bash's feature set, evolving with new options in subsequent releases.