On Unix-like operating systems, shopt is a builtin command of the Bash shell that enables or disables options for the current shell session.

Description

Use shopt to change any of the Options listed below.

  • Description
  • Syntax
  • Options
  • Examples
  • Related commands
  • Bash builtins help
  • Linux commands help

shopt is similar to, but different than, the set builtin. If you want to change the behavior of bash as if it had been invoked with different command line options, use set.

Syntax

shopt [-o] [-p] [-q] [-s] [-u] [optname…]

The shopt builtin command takes the following options and arguments:

Options

The following options modify the behavior of bash, and can be set or unset using shopt.

Examples

shopt

Print a list of all available options and their values.

  • The -F option to the declare builtin displays the source file name and line number corresponding to each function name supplied as an argument.If the command run by the DEBUG trap returns a non-zero value, the next command is skipped and not executed.If the DEBUG trap’s command returns a value of 2, and the shell is executing in a subroutine, a call to return is simulated.BASH_ARGC and BASH_ARGV are updated as described in their descriptions.Function tracing is enabled: command substitution, shell functions, and subshells invoked with ( command ) inherit the DEBUG and RETURN traps.Error tracing is enabled: command substitution, shell functions, and subshells invoked with ( command ) inherit the ERR trap.

shopt -p

Same as above; print a list of all available options and their values.

shopt -s

Print a list of all options that are currently set.

shopt -s globstar

Set the globstar option.

shopt -u cmdhist histappend

Unset the cmdhist and histappend options.

shopt -q globstar; echo $?

Check if the globstar option is set, and return an exit status instead of printing the result. In this case, the globstar option is unset, so the exit status is TRUE (zero). This value is stored in the ? shell variable, which is then printed to the terminal using echo. Output:

0

shopt -q globstar cmdhist histappend; echo $?

Return FALSE (a non-zero value) if any of globstar, cmdhist, or histappend options are not currently set. Output:

1

set — Set the value of shell options and positional parameters.