Recientemente encontré el comando:command
que no tiene entrada manual pero la ayuda se muestra de la siguiente manera:
$ 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.
Es command -v
es una alternativa de which
?
Qué argumentos acepta este comando y cómo/cuándo usar el command
?
Mejor respuesta
command
es un bash incorporado como podemos ver:
[email protected]:~$ type command
command is a shell builtin
Entonces sabemos command
es proporcionado por nuestro shell, bash. Profundizando en man bash
podemos ver cual es su uso:
(de man bash
):
command [-pVv] command [arg ...]
Run command with args suppressing the normal shell function
lookup. Only builtin commands or commands found in the PATH are
executed. If the -p option is given, the search for command is
performed using a default value for PATH that is guaranteed to
find all of the standard utilities. If either the -V or -v
option is supplied, a description of command is printed. The -v
option causes a single word indicating the command or file name
used to invoke command to be displayed; the -V option produces a
more verbose description. If the -V or -v option is supplied,
the exit status is 0 if command was found, and 1 if not. If
neither option is supplied and an error occurred or command
cannot be found, the exit status is 127. Otherwise, the exit
status of the command builtin is the exit status of command.
Esencialmente, usaría command
para omitir la "búsqueda de función normal". Por ejemplo, digamos que tenía una función en su .bashrc
:
function say_hello() {
echo 'Hello!'
}
Normalmente, cuando ejecutas say_hello
en su terminal bash encontraría la función llamada say_hello
en tu .bashrc
antes encontró, digamos, una aplicación llamada say_hello
. Usando:
command say_hello
hace que bash pase por alto su función de búsqueda normal y vaya directamente a las funciones integradas o a su $PATH
. Tenga en cuenta que esta función busca también incluir alias. Usando command
omitirá funciones y alias.
Si el -p
se proporciona la opción bash omite su $PATH
personalizado y utiliza su propio valor predeterminado.
El -v
o -V
flags bash imprime una descripción (abreviatura de -v
) , anhela -V
) del comando.
Nota:Como señaló souravc en los comentarios, se puede encontrar un método más fácil para encontrar información sobre las funciones integradas de shell aquí:¿Cómo hacer que `man` funcione para los comandos y palabras clave integrados de shell?