According to help command
, the help of bash, command
can be used to trigger the external program x, if x exists as a builtin function too:
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.
When testing with time
, this works as expected and uses the external program /bin/time
, but when I try:
command echo --help
# the output is
--help
which is the expected behavior for the builtin echo
.
Using xubuntu 22.04, bash 5.1.16 /bin/echo --help
works as expected.
Do I misunderstand the command
command? Or why doesn't it work as announced? How can I find out?
GNU bash, Version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
It does work as announced: it suppresses shell function lookup, not built-in lookup. The effect with
time
is misleading:time
is a reserved word, not a built-in, and only at the start of a pipeline. Incommand time
, the pipeline is started bycommand
, so the onlytime
it could have executed was the external one.To see the difference, define a function:
And compare
echo
withcommand echo
. (You can remove the function withunset -f echo
.)To see what something is, use
type
: