How do I control options for the current bash shell session?



  • Man page for bash.

    shopt built-in is used with the bash shell , Where as set built-in was traditionally used with other shells, but the functionality still exists in bash. As with both if you need to set options permanently store them in your .bashrc file.

           shopt [-pqsu] [-o] [optname ...]
                  Toggle the values of settings controlling optional shell  behav‐
                  ior.   The settings can be either those listed below, or, if the
                  -o option is used, those available with the -o option to the set
                  builtin command.  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.  The -p option causes output to be
                  displayed in a form that may be reused as input.  Other  options
                  have the following meanings:
                  -s     Enable (set) each optname.
                  -u     Disable (unset) each optname.
                  -q     Suppresses  normal output (quiet mode); the return status
                         indicates whether the optname is set or unset.  If multi‐
                         ple  optname arguments are given with -q, the return sta‐
                         tus is zero if all optnames are enabled; non-zero  other‐
                         wise.
                  -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,  shopt
                  shows  only  those options which are set or unset, respectively.
                  Unless otherwise noted, the shopt options are  disabled  (unset)
                  by default.
    
                  The  return  status when listing options is zero if all optnames
                  are enabled, non-zero  otherwise.   When  setting  or  unsetting
                  options,  the  return  status is zero unless an optname is not a
                  valid shell option.
    

    shopt used to set and unset options for the current shell session

    DIsplay current settings.

    $ shopt
    autocd          off
    cdable_vars     off
    cdspell         off
    checkhash       off
    checkjobs       off
    checkwinsize    on
    cmdhist         on
    compat31        off
    compat32        off
    compat40        off
    compat41        off
    compat42        off
    compat43        off
    complete_fullquote      on
    direxpand       off
    dirspell        off
    dotglob         off
    execfail        off
    expand_aliases  on
    extdebug        off
    extglob         on
    extquote        on
    failglob        off
    force_fignore   on
    globasciiranges off
    globstar        off
    gnu_errfmt      off
    histappend      on
    histreedit      off
    histverify      off
    hostcomplete    off
    huponexit       off
    inherit_errexit off
    interactive_comments    on
    lastpipe        off
    ...
    ...
    ...
    

    Enable an option. Using the -s option.

    $ shopt -s mailwarn
    $ shopt mailwarn
    mailwarn        on
    

    Disable an option. Using the -u option

    $ shopt mailwarn
    mailwarn        on
    $ shopt -u mailwarn
    $ shopt mailwarn
    mailwarn        off
    

    To read about all the shopt settings check the bash man page.


Log in to reply
 

© Lightnetics 2024