Re: Why does the command builtin not circumvent invocation of builtins?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 30/08/2024 19:28, Anselm Schüler wrote:
The dash(1) manpage reads:

command [-p] [-v] [-V] command [arg ...]
       Execute the specified command but ignore shell functions when searching for it. (This is useful when you have a shell function with the same name as a builtin command.)

This implies that it does not ignore builtin commands, because otherwise it would not be useful for this purpose.

Because of this, I expected commands like command . or PATH= command true to fail. They don’t.

. and true are builtin commands, not shell functions (at least not by default), so they are found.

This is how it is meant to work. The parenthesised comment is there to highlight that you can do things such as

  echo() {                  # shell function
    command echo "$@" >>log # builtin command
    command echo "$@"       # builtin command
  }
  echo hello # call shell function to print both to log and to stdout

(Mind you, this is an intentionally silly example that nobody should write this way, it just demonstrates the concept.)

Here, it is important for "command echo" to find the builtin command, not the shell function. If it found the shell function, this would recurse infinitely. If it did not find the builtin command, this would not necessarily print anything.

This also matches how "command" works in other shells as well.

Cheers,
Harald van Dijk




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux