l0b*_*0b0 4 bash shell-builtin
运行只是不builtin打印任何内容并返回退出代码 0。这符合help builtin,将所有参数显示为可选。但为什么这个空操作不是错误?有这个用例吗?更有用的结果是错误代码,或者更好的是列出当前可用的内置函数。
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
Run Code Online (Sandbox Code Playgroud)
即使没有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
Run Code Online (Sandbox Code Playgroud)
所有参数都是可选的,但$? -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
Run Code Online (Sandbox Code Playgroud)
有一个新部分“退出状态”,command它仍然是一个可选参数。甚至比 3.x 还要糟糕。其他内置插件也是如此。
所以,你是对的。Bash 内置插件是一团糟,应该修复。