很简单的问题,真的...
运行时会发生什么:builtin
?
的返回类型echo $?
是0
。
这意味着该命令很可能已成功运行。
那么,跑步到底有什么作用builtin
呢?
当您希望将 shell 内置函数重新实现为 shell 函数,但需要在函数内执行内置函数时,这很有用。
$ type echo
echo is a shell builtin
$ function echo(){ builtin echo "'$1'"; }
$ echo hi
'hi'
Run Code Online (Sandbox Code Playgroud)
help builtin
Run Code Online (Sandbox Code Playgroud)
builtin: builtin [shell-builtin [arg ...]] 执行 shell 内置函数。
Run Code Online (Sandbox Code Playgroud)Execute SHELL-BUILTIN with arguments ARGs without performing command lookup. This is useful when you wish to reimplement a shell builtin as a shell function, but need to execute the builtin within the function. Exit Status: Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is not a shell builtin.