什么是 bash 上的“命令”?

Alb*_*era 1 linux bash shell-script

如果我command在我的终端上输入,我不会得到“找不到命令”,并且退出代码是 0。我认为这意味着command实际上在 bash 上做了一些事情。

此外,command -h返回:

bash: command: -h: invalid option
command: usage: command [-pVv] command [arg ...]
Run Code Online (Sandbox Code Playgroud)

它是干什么用的?

Wil*_*ard 5

来自help command

$ 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.
Run Code Online (Sandbox Code Playgroud)

作为更一般的说明,而不是仅仅-h在您不知道命令的作用时使用,您应该尝试:

type -a command
Run Code Online (Sandbox Code Playgroud)

在这种情况下,它会告诉你它是一个内置的 shell。

help command
Run Code Online (Sandbox Code Playgroud)

对 shell 内置函数有好处。对于其他命令(实际上适用于 shell 内置命令),请尝试

man somecommand
Run Code Online (Sandbox Code Playgroud)

另外,-h是不是一定的“帮助”选项。如果您不知道命令的作用,那可能不是一个安全的假设。更安全的是--help

somecommand --help
Run Code Online (Sandbox Code Playgroud)

(常用命令这里-h是一个有效的选择,但确实不是意味着“帮助”是lsfreedfdu。的这些都是仅供参考,但前提是-h仅会平均“帮助”是一个危险的假设。)

  • 虽然帮助没有这么说,但`command xyz` 也隐含地抑制了别名`xyz`,因为`xyz` 不再是第一个标记。 (2认同)