
A execução simplesmente builtin
não imprime nada e retorna o código de saída 0. Isso está de acordo com help builtin
, que mostra todos os parâmetros como opcionais. Mas por que isso não é um erro? Existe um caso de uso para isso? Um resultado mais útil seria um código de erro ou, melhor ainda, uma lista dos recursos integrados atualmente disponíveis.
Responder1
Os recursos internos do Bash são inconsistentes e mal documentados.
Aqui está um exemplo:
$ 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
Mesmo sem command
o código de retorno $? -eq 0
e não há erro no std err
.
Outro:
$ 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
Todos os argumentos são opcionais, mas retorna $? -eq 1
quando não há nenhum.
Até compilei o mais novo Bash 4.2 e aqui estão meus resultados:
$ 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
Há uma nova seção "Status de saída" e command
ainda é um argumento opcional. Ainda pior que 3.x. O mesmo para outros integrados.
Então, você está certo. Os recursos internos do Bash são uma bagunça e devem ser consertados.