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.

FORMAT:

 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.

shanky@shankysportal $ 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. 

shanky@shankysportal $ shopt -p
shopt -u autocd
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -u checkjobs
shopt -s checkwinsize
shopt -s cmdhist

shanky@shankysportal $ shopt|grep histappend
histappend      off
shanky@shankysportal $ shopt -p |grep histappend
shopt -u histappend
 


Below are the remaining options:

              -s     Enable (set) each optname.

shanky@shankysportal $ shopt -s histappend
shanky@shankysportal $ shopt -p |grep histappend
shopt -s histappend

shanky@shankysportal $ shopt|grep histappend
histappend      on


              -u     Disable (unset) each optname.

shanky@shankysportal $ shopt -u histappend
shanky@shankysportal $ shopt|grep histappend
histappend      off

shanky@shankysportal $ 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:

              cdable_vars
                      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.
              cdspell

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.
              checkhash
                      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.
              checkwinsize
                      If set, bash checks the window size after each command and, if necessary, updates  the  values of LINES and COLUMNS.
              cmdhist

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.

               dotglob

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

                   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.
              expand_aliases
                      If  set,  aliases  are  expanded  as described above under ALIASES.  This option is enabled by default for interactive shells.
              extdebug
                      If set, behavior intended for use by debuggers is enabled:
              extglob

If set, the extended pattern matching features described above under  Pathname  Expansion  are enabled.
              extquote
                      If  set,  $'string' and $"string" quoting is performed within ${parameter} expansions enclosed in double quotes.  This option is enabled by default.
              failglob
                      If set, patterns which fail to match filenames during pathname expansion result in  an  expansion error.
              force_fignore
                      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.
                gnu_errfmt
                      If set, shell error messages are written in the standard GNU error message format.
              histappend
                      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.
              histreedit
                      If set, and readline is being used, a user is given the opportunity to re-edit a  failed  history substitution.
              histverify
                      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.
              hostcomplete
                      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.
              huponexit
                      If set, bash will send SIGHUP to all jobs when an interactive login shell exits.
              interactive_comments
                      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.
              lithist

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.
              login_shell
                      The shell sets this option if it is started as a login  shell  (see  INVOCATION  above).   The value may not be changed.
              mailwarn
                      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.
              no_empty_cmd_completion
                      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.
              nocaseglob
                      If  set,  bash matches filenames in a case-insensitive fashion when performing pathname expansion (see Pathname Expansion above).
              nocasematch
                      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.


Example:

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';
matching


        

      nullglob
                      If  set, bash allows patterns which match no files (see Pathname Expansion above) to expand to a null string, rather than themselves.
              progcomp
                      If set, the  programmable  completion  facilities  (see  Programmable  Completion  above)  are enabled.  This option is enabled by default.
              promptvars
                      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.
              restricted_shell
                      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.
              shift_verbose
                      If  set,  the shift builtin prints an error message when the shift count exceeds the number of positional parameters.
               sourcepath
                      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.
              xpg_echo
                      If set, the echo builtin expands backslash-escape sequences by default.

 
 

Category: Open System-Linux | Views: 1414 | 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:


[2014-03-17][Open System-Linux]
AWK command for scanning and analysing a large file in Linux
[2016-01-23][Open System-Linux]
Some useful examples of netstat command in Linux for network statistics
[2014-04-22][Open System-Linux]
xmllint : a command line xml tool to view and find errors in XML file
[2014-10-25][Open System-Linux]
XMLWF command in Linux to check/validate/parse an XML file
[2015-06-08][Open System-Linux]
CHAGE command in LINUX

Total comments: 0
ComForm">
avatar