シェル組み込みコマンドに適切なマニュアルページがないのはなぜですか?

シェル組み込みコマンドに適切なマニュアルページがないのはなぜですか?

すべてのシェル組み込み機能は同じマニュアルページを共有します。

BUILTIN(1)                BSD General Commands Manual               BUILTIN(1)

NAME
     builtin, !

など。

次に、シェル組み込みコマンドが何であるかを説明する短い段落と、次のようなリストがあります。

  Command       External    csh(1)    sh(1)
       !             No          No        Yes
       %             No          Yes       No

しかし、これを行うと、man grep次のような結果が得られます。

  • 昆虫
  • 歴史
  • また、見ることができます
  • 基準
  • 説明する

など。

シェル組み込み関数には、-Aまたはなどの自己記録、説明、およびパラメータはありませんか-r?マニュアルページでこれらのコンテンツが提供されていないのはなぜですか、それを正確かつ効率的に使用する方法を学ぶ方法は?

ベストアンサー1

組み込み関数はシェルの一部であるからです。彼らが持っているすべてのエラーや記録はシェル自体のものです。これはスタンドアロンコマンドではなく、ビルドされたシェルの外部にも存在しません。

少なくともそれに対応するのはコマンドbashです。helpたとえば、

$ help while
while: while COMMANDS; do COMMANDS; done
    Execute commands as long as a test succeeds.

    Expand and execute COMMANDS as long as the final command in the
    `while' COMMANDS has an exit status of zero.

    Exit Status:
    Returns the status of the last command executed.

すべてのbash組み込み機能にはhelpページがあります。それ自体もhelp

$ help help
help: help [-dms] [pattern ...]
    Display information about builtin commands.

    Displays brief summaries of builtin commands.  If PATTERN is
    specified, gives detailed help on all commands matching PATTERN,
    otherwise the list of help topics is printed.

    Options:
      -d    output short description for each topic
      -m    display usage in pseudo-manpage format
      -s    output only a short usage synopsis for each topic matching
        PATTERN

    Arguments:
      PATTERN   Pattern specifiying a help topic

    Exit Status:
    Returns success unless PATTERN is not found or an invalid option is given.

@mikeservsedのスクリプトに触発され、Perlを使用してマニュアルページの関連部分を印刷する小さな関数があります。シェルの初期化ファイル(~/.bashrcbashの場合)に次の行を追加します。

manperl(){ man "$1" | perl -00ne "print if /^\s*$2\b/"; }

次に、マニュアルページとセクション名を指定して実行します。

$ manperl bash while
       while list-1; do list-2; done
       until list-1; do list-2; done
              The while command continuously executes the list list-2 as long as the last command in the list list-1 returns an exit
              status of zero.  The until command is identical to the while command, except that the test is negated; list-2 is  exe‐
              cuted  as  long  as the last command in list-1 returns a non-zero exit status.  The exit status of the while and until
              commands is the exit status of the last command executed in list-2, or zero if none was executed.

$ manperl grep SYNOPSIS
SYNOPSIS
       grep [OPTIONS] PATTERN [FILE...]
       grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

$ manperl rsync "-r"
       -r, --recursive
              This tells rsync to copy directories recursively.  See also --dirs (-d).

おすすめ記事