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 내장 기능은 엉망이므로 고쳐야 합니다.

관련 정보