Home » 2014 » September » 24 » Set, unset, display shell behaviour options : SHOPT command in Linux

8:53 AM
Set, unset, display shell behaviour options : SHOPT command in Linux

Share on Google+

SHOPT : Toggle the values of variables controlling optional shell behavior.


 shopt [-pqsu] [-o] [optname ...]

   With no options, or with  the  -p option, a list of all settable options is displayed, with an indication of whether or not each is set.

[email protected] $ shopt
autocd          off
cdable_vars     off
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    on
cmdhist         on

 The -p option causes output to be displayed in a form that may be reused as input. 

[email protected] $ shopt -p
shopt -u autocd
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -u checkjobs
shopt -s checkwinsize
shopt -s cmdhist

[email protected] $ shopt|grep histappend
histappend      off
[email protected] $ shopt -p |grep histappend
shopt -u histappend

Below are the remaining options:

              -s     Enable (set) each optname.

[email protected] $ shopt -s histappend
[email protected] $ shopt -p |grep histappend
shopt -s histappend

[email protected] $ shopt|grep histappend
histappend      on

              -u     Disable (unset) each optname.

[email protected] $ shopt -u histappend
[email protected] $ shopt|grep histappend
histappend      off

[email protected] $ shopt -p |grep histappend
shopt -u histappend

              -q     Suppresses  normal  output (quiet mode); the return status indicates whether the optname is set or unset.  If multiple optname arguments are given with -q, the return status is  zero  if  all optnames are enabled; non-zero otherwise.
              -o     Restricts the values of optname to be those defined for the -o option to the set builtin.

              If  either  -s  or -u is used with no optname arguments, the display is limited to those options which are set or unset, respectively.  Unless otherwise noted, the shopt options  are  disabled  (unset)  by default.


The list of shopt options is given below:

                      If  set,  an  argument  to the cd builtin command that is not a directory is assumed to be the name of a variable whose value is the directory to change to.

If set, minor errors in the spelling of a directory component in a cd  command  will  be  corrected.   The errors checked for are transposed characters, a missing character, and one character too many.  If a correction is found, the corrected file name is printed, and the command proceeds.  This option is only used by interactive shells.
                      If set, bash checks that a command found in the hash table exists before trying to execute it. If a hashed command no longer exists, a normal path search is performed.
                      If set, bash checks the window size after each command and, if necessary, updates  the  values of LINES and COLUMNS.

If  set, bash attempts to save all lines of a multiple-line command in the same history entry.
                      This allows easy re-editing of multi-line commands.


If set, bash includes filenames beginning with a `.' in the results of pathname expansion.

                   If set, a non-interactive shell will not exit if it cannot execute the file  specified  as  an argument to the exec builtin command.  An interactive shell does not exit if exec fails.
                      If  set,  aliases  are  expanded  as described above under ALIASES.  This option is enabled by default for interactive shells.
                      If set, behavior intended for use by debuggers is enabled:

If set, the extended pattern matching features described above under  Pathname  Expansion  are enabled.
                      If  set,  $'string' and $"string" quoting is performed within ${parameter} expansions enclosed in double quotes.  This option is enabled by default.
                      If set, patterns which fail to match filenames during pathname expansion result in  an  expansion error.
                      If  set,  the  suffixes specified by the FIGNORE shell variable cause words to be ignored when performing word completion even if the ignored words are the only possible  completions.   See SHELL VARIABLES above for a description of FIGNORE.  This option is enabled by default.
                      If set, shell error messages are written in the standard GNU error message format.
                      If  set,  the history list is appended to the file named by the value of the HISTFILE variable when the shell exits, rather than overwriting the file.
                      If set, and readline is being used, a user is given the opportunity to re-edit a  failed  history substitution.
                      If  set,  and  readline is being used, the results of history substitution are not immediately passed to the shell parser.  Instead, the resulting line is loaded into the  readline  editing buffer, allowing further modification.
                      If  set,  and  readline is being used, bash will attempt to perform hostname completion when a word containing a @ is being completed (see Completing under READLINE above).  This is enabled by default.
                      If set, bash will send SIGHUP to all jobs when an interactive login shell exits.
                      If  set, allow a word beginning with # to cause that word and all remaining characters on that line to be ignored in an interactive shell (see COMMENTS above).  This option  is  enabled  by default.

If  set,  and the cmdhist option is enabled, multi-line commands are saved to the history with
                      embedded newlines rather than using semicolon separators where possible.
                      The shell sets this option if it is started as a login  shell  (see  INVOCATION  above).   The value may not be changed.
                      If set, and a file that bash is checking for mail has been accessed since the last time it was checked, the message ``The mail in mailfile has been read'' is displayed.
                      If set, and readline is being used, bash will not attempt to search the PATH for possible completions when completion is attempted on an empty line.
                      If  set,  bash matches filenames in a case-insensitive fashion when performing pathname expansion (see Pathname Expansion above).
                      If set, bash matches patterns in a case-insensitive fashion  when  performing  matching  while executing case or [[ conditional commands.

See below example, if we set this option, "a" equals "A" performing case insensitive comparision.


Prompt:~> shopt -u nocasematch && shopt|grep nocasematch
nocasematch     off

Prompt:~> [[ "A" == "a" ]] && echo 'matching'||echo 'not matching';
not matching

Prompt:~> shopt -s nocasematch && shopt|grep nocasematch
nocasematch     on

Prompt:~> [[ "A" == "a" ]] && echo 'matching'||echo 'not matching';


                      If  set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.
                      If set, the  programmable  completion  facilities  (see  Programmable  Completion  above)  are enabled.  This option is enabled by default.
                      If  set,  prompt  strings undergo parameter expansion, command substitution, arithmetic expansion, and quote removal after being expanded as described in PROMPTING above.  This option  is enabled by default.
                      The  shell  sets this option if it is started in restricted mode (see RESTRICTED SHELL below). The value may not be changed.  This is not reset when the startup files are executed, allowing the startup files to discover whether or not a shell is restricted.
                      If  set,  the shift builtin prints an error message when the shift count exceeds the number of positional parameters.
                      If set, the source (.) builtin uses the value of PATH to find  the  directory  containing  the file supplied as an argument.  This option is enabled by default.
                      If set, the echo builtin expands backslash-escape sequences by default.


Category: Open System-Linux | Views: 1208 | Added by: shanky | Tags: shopt, SHOPT command in linux, set unset shell behaviour, display shell behaviour, shanky portal, set optional shell variable in linu, shankys portal | Rating: 0.0/0

Related blogs

You may also like to see:

[2015-09-09][Open System-Linux]
Some funny and cool commands in Linux
[2014-02-19][Open System-Linux]
Shift Key is not working!! Mapping keyboard keys from one to another
[2015-01-18][Open System-Linux]
The JAR archiving tool in Linux
[2014-12-22][Open System-Linux]
Key mapping inside VI editor
[2015-06-03][Open System-Linux]
STAT command : check file or filesystem statistics

Total comments: 0