Javatpoint Logo
Javatpoint Logo

What is Bash shopt built-in command?

Shopt is a built-in command of the Bash shell that controls whether certain options are enabled or disabled for the current shell session on Unix-like operating systems.

What is Bash shopt built-in command

Description:

Any of the Options listed below can be modified using shopt.

The shopt is similar but distinct compared to the built-in set. Use set to modify how bash behaves such that it behaves as though a different set of command line options were used to launch it.

Syntax:

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

  • Optname:
    It is the title of a bash option. It is possible to specify multiple option names, each one separated by a space.
  • -o:
    Only the values recognized by the set builtin command should be used as optname values.
  • -p:
    Write down every shell option together with its current value. If no options are provided, this is the default action.
  • -q:
    It is hushed mode. No output is provided; instead, an error status is returned.The error status for a single optname is TRUE (zero) if the option is set andFALSE (non-zero) if it is not.
    If more than one optname is used, the error status for each optname is either TRUE if all options are set or FALSE if any of the options are not set.
  • -s:
    If optnames are given, Set the options. List all of the choices that are currently selected if no optnames are given.
  • -u:
    It is utilized to disable optnames.

Options:

The following settings can be set or unset with Shopt, and they affect how bash behaves.

  • Autocd:
    If it is set, a directory-named command is run as if it were the cd command's parameter. This option is only available in interactive shells.
  • cdable_vars:
    If it is set, a non-directory cd command argument is taken to be the name of the variable whose value is the directory to shift to.
  • Cdspell :
    Minor spelling mistakes in a directory component in a cd command are fixed if the flag is set. Transposed characters, missing characters, and extra characters are the mistakes that are looked for. If a correction is discovered, the command continues after printing the updated file name. Interactive shells are the only ones that use this option.
  • Checkhash :
    If it is set, before attempting to execute a command it finds in the hash table of commands it previously remembered, and bash verifies if the command exists. A standard path search is carried out if a hashed command no longer exists. Check out the hash built-in command for further details on the hash table that bash keeps up to date.
  • Checkjobs:
    When this option is enabled, bash finishes an interactive shell by listing the status of any halted and active jobs. If any jobs are already running, it results in a delay of the exit until a subsequent exit attempt without an intervening command is made. If any jobs are stopped, the shell never exits immediately.
  • Checkwinsize:
    Bash changes the values of the LINES and COLUMNS shell variables if necessary after each command if the option is set. Bash also checks the window size of the active terminal window if the option is set.
  • Cmdhist:
    If this option is selected, bash tries to save all of the lines from a multi-line command in the same historical record. Multi-line commands can now be easily edited again.
  • compat31:
    If this option is set, the behavior of bash with regard to quoted arguments to the = operator in [[conditional commands]] is changed to that of version 3.1.
  • compat32:
    When employing the and > operators of the [[conditional command]], bash behaves as it did in version 3.2 with regard to comparisons of strings that are particular to a given locale. Versions of Bash prior to bash-4.1 use the ASCII collation sequence and strcmp; bash-4.1 and later utilize the current locale's collation sequence and strcoll.
  • compat40:
    If it is true, bash adopts the behavior of bash version 4.0 with regard to the effect of interrupting a command list and locale-specific string comparisons when using the [[conditional command's]] and > operators.
  • compat41:
    If it is set, a single quotation within a double-quoted argument expansion is treated as a special character by bash when it is in POSIX mode. The characters between the single quotations are regarded as quoted text, and the single quotes must match (have an even number). This is how bash version 4.1's POSIX mode behaves. The default behavior of bash is still the same as in earlier versions.
  • Direxpand:
    The bash replaces directory names with the outcomes of word expansion depending on whether this option is selected when performing file name completion. As a result, the readline editing buffer's contents are modified. Bash tries to keep track of the user's input if the option is not set.
  • Dirspell:
    In the event that the directory name provided at the beginning does not exist, bash will attempt spelling correction on directory names if this option is specified.
  • Dotglob:
    If it is enabled, path name globbing includes file names starting with a '.' in the bash output.
  • Execfail:
    If it is enabled, a non-interactive shell will continue running even if it is unable to open the file given as an argument to the exec built-in command. If exec fails, an interactive shell does not terminate.
  • expand_aliases:
    Aliases are expanded according to the bash aliases documentation if set. This option is turned on by default for interactive shells.
  • Extdebug :

If configured, the following behavior is activated by debuggers:

  1. For each function name provided as an input, the declare builtin's -F option displays the source file name and line number corresponding to it.
  2. The subsequent command is skipped and not executed if the command executed by the DEBUG trap returns a value other than zero.
  3. The shell simulates a call to return if the DEBUG trap's command returns a value of 2 while the shell is running in a function.
  4. Updates have been made to BASH_ARGC and BASH_ARGV in accordance with their descriptions.
  5. When function tracing is enabled, command substitution, shell functions, and subshells executed with (command) inherit the DEBUG and RETURN traps.
  6. Command substitution, shell functions, and subshells executed with (command) inherit the ERR trap when error tracing is enabled.
  • Extglob:
    The additional pattern matching capabilities provided by bash path name expansion are enabled if it configured.
  • Extquote:
    If it is enabled, double quotes around $parameter expansions will be used to quote $'string' and $"string" within them. Default settings have this option turned on.
  • Failglob:
    If it is enabled, patterns that don't match file names when the path name is expanded cause an expansion error.
  • force_fignore:
    When the FIGNORE shell variable is set, words that have the given suffixes are disregarded when word completion is performed, even if those words are the only ones that may possibly complete the sentence. Default settings have this option turned on.
  • Globstar:
    If it is set, all files and zero or more folders and subdirectories are included in the pattern ** used in a path name expansion context. Only directories and subdirectories match if the pattern is followed by a /.
  • gnu_errfmt:
    Shell error messages are written using the standard GNU error message format if the setting is present.
  • Histappend:
    The history list is not overwritten when the shell terminates but rather is added to the file indicated by theHISTFILE variable if the option is set.
  • Histreedit:
    If the option is set and readline is being utilized, a user is given the option to redo a failed history substitute.
  • Histverify:
    The outcomes of history substitution are delayed from being sent right away to the shell parser if set and readline are both being used. As an alternative, the generated line is loaded into the readline editing buffer to enable for additional customization.
  • Hostcomplete:
    Whenever a word with a @ is finished, bash tries to complete the hostname if the option is specified and readline is being utilized. Normally, it is turned on.
  • Huponexit:
    If it is set, bash will send the SIGHUP signal to all running processes upon the termination of an interactive login shell.
  • interactive_comments :
    If it is enabled, a word starting with # will, in an interactive shell, cause that word and the rest of the letters on that line to be disregarded. By default, this option is turned on.
  • Lastpipe :
    In the event that this option is set and job control is not active, the shell executes the final command of any pipeline that was not run in the background in the current shell environment.
  • Lithest:
    Whenever possible, multi-line commands are saved to the history with embedded newlines rather to using semicolons if the cmdhist option is enabled and configured.
  • Mailwarn:
    The message "The mail in mailfile has been read" is shown if the option is specified and a file that bash is searching for mail was accessed since it was last checked.
  • no_empty_cmd_completion:
    When a completion attempt is made on an empty line, bash does not try to scan the PATH for potential completions if set, and readline are both active.
  • Nocaseglob:
    Using this option causes path name expansion in bash to match file names without regard to the case.
  • Nocasematch:
    If it is set, while case-sensitive or [[conditional commands]] are being executed, bash matches patterns without taking into account the case.
  • Nullglob:
    When this option is enabled, bash allows patterns that match no files to expand to a null string rather than to them.
  • progcomp:
    The facilities for programmed completion are activated if it is set.
  • Promptvars:
    If it is enabled, prompt strings are enlarged before being replaced with commands, expanded arithmetically, and have quotes removed. Default settings have this option turned on.
  • shift_verbose:
    When the number of shifts is greater than the number of positions arguments, the shift built-in prints an error message if the option is selected.
  • Sourcepath:
    If it is set, the value of the shell variable PATH is used by the source built-in to locate the directory holding the file that was passed as an input. Default settings have this option turned on.

Next TopicWhat is LKGC?





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA