您如何获得可用`shopt` 选项的描述?

bnj*_*jmn 9 bash shopt

访问内置任何可用 Shell 选项的本地文档的规范方式是什么shopt

我正在使用 Ubuntu 12.04 并且可以运行help shopt以获取有关功能的描述shopt

shopt: shopt [-pqsu] [-o] [optname ...]
    Set and unset shell options.
    ...
Run Code Online (Sandbox Code Playgroud)

我可以列出各种 Shell 选项及其值(shoptshopt -p)。但是,我如何在不离开 Linux 机器的舒适环境中了解每个人的实际情况?我不是在网上寻找描述。是否有man页面或我遗漏的东西?

Chr*_*own 10

请参阅“shell 内置命令”部分man bash;它有一个shopt描述所有可用 shell 选项的条目。这是摘录:

   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.

          [...]
Run Code Online (Sandbox Code Playgroud)


Gil*_*il' 5

您可以在手册页的shopt内置说明下找到选项列表。要在选项列表中打开手册页,您可以使用less允许您在启动时运行命令(例如搜索)的功能:

PAGER='less "+/^ *The list of shopt"' man bash
Run Code Online (Sandbox Code Playgroud)

要在信息中查看此文档:

info --index shopt bash
Run Code Online (Sandbox Code Playgroud)

如果要提取手册页的相关部分:

man bash | sed '/^ *The list of shopt/, /^ *suspend / p' | sed '$d'
Run Code Online (Sandbox Code Playgroud)

或(更好,因为它删除了缩进)

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

如果您想提取一个选项的描述(例如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}'
Run Code Online (Sandbox Code Playgroud)