GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Uso del comando:`comando`?

Recentemente ho trovato il comando:command che non ha immissione manuale ma la guida viene visualizzata come segue:

$ 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.

È command -v è alternativa a which ?

Quali argomenti sono accettati da questo comando e come/quando utilizzare il command ?

Migliore risposta

command è un integrato di bash come possiamo vedere:

[email protected]:~$ type command
command is a shell builtin

Quindi conosciamo il command è fornito dalla nostra shell, bash. Scavando in man bash possiamo vedere a cosa serve:

(da 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.  

In sostanza dovresti usare command per aggirare la “normale ricerca di funzioni”. Ad esempio, supponiamo di avere una funzione nel tuo .bashrc :

function say_hello() {
   echo 'Hello!'
}

Normalmente, quando esegui say_hello nel tuo terminale bash troverebbe la funzione denominata say_hello nel tuo .bashrc prima ha trovato, diciamo, un'applicazione chiamata say_hello . Usando:

command say_hello  

fa in modo che bash ignori la sua normale funzione di ricerca e vada direttamente ai builtin o al tuo $PATH . Nota che questa funzione cerca anche includere alias. Usando command ignorerà sia le funzioni che gli alias.

Correlati:questi errori SATA sono pericolosi?

Se il -p l'opzione è fornita bash bypassa il tuo $PATH personalizzato e utilizza la propria impostazione predefinita.

Il -v o -V flags bash stampa una descrizione (abbreviazione di -v , lungo per -V ) del comando.

Nota:come sottolineato da Souravc nei commenti, un metodo più semplice per trovare informazioni sui builtin della shell può essere trovato qui:Come far funzionare `man` per i comandi e le parole chiave incorporati nella shell?


Ubuntu
  1. Come utilizzare il comando sudo in Linux

  2. Come utilizzare il comando DD Show Progress in Linux?

  3. Come usare il comando Su in Linux

  4. Come usare ssh-keyscan su Ubuntu

  5. Come usare ssh-agent su Ubuntu

Come utilizzare un comando file in Linux

Uso del comando principale in Linux

Come usare il comando pkill

Come utilizzare il comando LDD in Linux

Come usare il comando PS

Come usare il comando TOP