Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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.
          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 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
                  shells.

          [...]
share|improve this answer

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}'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.