Bashの組み込みパラメータがオプションであるのはなぜですか?

Bashの組み込みパラメータがオプションであるのはなぜですか?

実行すると、builtin何も印刷されず、終了コード0が返されます。これはhelp builtin、すべてのパラメータをオプションとしてマークすることと一致します。しかし、なぜこれがランダムエラーではないのですか?これにユースケースはありますか?より有用な結果は、エラーコードまたはさらに、現在利用可能な組み込み関数のリストです。

ベストアンサー1

Bashの組み込み機能は一貫性がなく、文書化もうまくいきません。

例は次のとおりです。

$ help command
command: command [-pVv] command [arg ...]
    Runs COMMAND with ARGS ignoring shell functions.  If you have a shell
    function called 'ls', and you wish to call the command `ls', you can
    say "command ls".  If the -p option is given, a default value is used
    for PATH that is guaranteed to find all of the standard utilities.  If
    the -V or -v option is given, a string is printed describing COMMAND.
    The -V option produces a more verbose description.
$ command; echo $?
0

command戻りコードがなくても$? -eq 0エラーは発生しませんstd err

もう一つ:

$ help disown
disown: disown [-h] [-ar] [jobspec ...]
    By default, removes each JOBSPEC argument from the table of active jobs.
    If the -h option is given, the job is not removed from the table, but is
    marked so that SIGHUP is not sent to the job if the shell receives a
    SIGHUP.  The -a option, when JOBSPEC is not supplied, means to remove all
    jobs from the job table; the -r option means to remove only running jobs.
$ disown; echo $?
-bash: disown: current: no such job
1

すべてのパラメータはオプションですが、$? -eq 1パラメータがない場合は返されます。

最新のBash 4.2をコンパイルしましたが、結果は次のとおりです。

$ help command
command: command [-pVv] command [arg ...]
    Execute a simple command or display information about commands.

    Runs COMMAND with ARGS suppressing  shell function lookup, or display
    information about the specified COMMANDs.  Can be used to invoke commands
    on disk when a function with the same name exists.

    Options:
      -p    use a default value for PATH that is guaranteed to find all of
        the standard utilities
      -v    print a description of COMMAND similar to the `type' builtin
      -V    print a more verbose description of each COMMAND

    Exit Status:
    Returns exit status of COMMAND, or failure if COMMAND is not found.
$ command; echo $?
0

新しいセクション「終了ステータス」があり、commandまだオプションのパラメータです。 3.xより悪いです。他の組み込みプログラムも同様です。

だから、あなたは正しいです。 Bashの組み込み機能はめちゃくちゃなので修正する必要があります。

おすすめ記事