What is the canonical way for accessing the local documentation on any available Shell Options builtin with shopt?

I'm using Ubuntu 12.04 and can run help shopt to get a description of what shopt does:

shopt: shopt [-pqsu] [-o] [optname ...]
    Set and unset shell options.

I can list the various Shell Options and their values (shopt or shopt -p). But how do I find out what each one actually does without leaving the comfort of my Linux box? I'm not looking for the descriptions online. Is there a man page or something I'm missing?

  • 1
    Quick Trick ~ man bash | grep "shopt" May 21, 2016 at 16:20

2 Answers 2


See the "shell builtin commands" section of man bash; it has an entry for shopt that describes all of the available shell options. Here is an excerpt:

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


          autocd  If  set,  a command name that is the name of a directory
                  is executed as if it were the argument to  the  cd  com-
                  mand.  This option is only used by interactive shells.
                  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 com-
                  ponent in a cd command will be  corrected.   The  errors
                  checked for are transposed characters, a missing charac-
                  ter, and one character too many.   If  a  correction  is
                  found,  the corrected file name is printed, and the com-
                  mand proceeds.  This option is only used by  interactive


You can find the list of options in the man page under the description of the shopt builtin. To open the man page at the list of options, you can use the less feature that lets you run a command such as a search when it starts:

PAGER='less "+/^ *The list of shopt"' man bash

To view this documentation in Info:

info --index shopt bash

If you want to extract the relevant part of the man page:

man bash | sed '/^ *The list of shopt/, /^ *suspend / p' | sed '$d'

or (nicer, as it removes the indentation)

man bash | awk '
    /^ *The list of shopt/ {indent=match($0, /[^ ]/)}
    /^ *suspend / && RSTART==indent {exit}
    indent {print substr($0, indent)}'

If you want to extract the description of one option (e.g. sourcepath):

man bash | awk -v target=sourcepath '
    /^ *The list of shopt/ {shopt=1}
    shopt && $1==target {getline; indent=match($0, /[^ ]/)}
    indent {if (match($0, /[^ ]/)>=indent) print substr($0, indent); else exit}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .