web-dev-qa-db-ja.com

利用可能な `shopt`オプションの説明をどのように取得しますか?

shoptで組み込まれている利用可能なシェルオプションのlocalドキュメントにアクセスするための標準的な方法は何ですか?

私はUbuntu 12.04を使用しており、help shoptを実行してshoptの機能の説明を取得できます。

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

さまざまなシェルオプションとその値(shoptまたはshopt -p)を一覧表示できます。しかし、Linuxボックスの快適さを残さずに、それぞれが実際に何をしているのかをどうやって知るのでしょうか? オンラインの説明 を探していません。 manページまたは私が見逃しているものはありますか?

7
bnjmn

man bashの「シェル組み込みコマンド」セクションを参照してください。使用可能なすべてのシェルオプションを説明するshoptのエントリがあります。以下は抜粋です。

   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.

          [...]
8
Chris Down

オプションのリストは、マニュアルページのshoptビルトインの説明の下にあります。オプションのリストでmanページを開くには、起動時に検索などのコマンドを実行できるless機能を使用できます。

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

このドキュメントを情報で表示するには:

info --index shopt bash

Manページの関連部分を抽出したい場合:

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

または(インデントを削除するため、より良い)

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

1つのオプションの説明を抽出する場合(例: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}'