Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

command - execute a simple command

&pagelevel(4)&pagelevel

command informs the shell that the arguments are to be executed as simple commands. The shell functions are not evaluated.

command also provides information about how a command name is interpreted by the shell (see Format 2).

Syntax


Format 1: command[ -p] command_name[ argument ...]
Format 2: command[ -v| -V] command_name



Format 1: command [ -p] command_name [ argument ...]

-p

The command search is performed using a default value for PATH which ensures that all standard commands can be found.

command_name

The name of a command or a special built-in command.

argument

One of the strings as an argument for command_name.


Format 2: command[ -v | -V] command_name

-v

A string is written to the standard output. This string specifies the path name or command which the shell uses to call command_name in the current shell environment.

  • Commands, regular built-in commands, command_names containing a slash as well as implementation-specific functions which are specified by the PATH variable are written as absolute path names.

  • Shell functions, special built-in commands and regular built-in commands which cannot be accessed via the definition in the PATH variable as well as reserved shell terms are specified as simple names.

  • An alias is written as a call line which represents the alias definition.

  • In other cases, no string is written to the output. The exit status specifies that the command could not be found.

The standard output is formatted as follows: "%s\n", <path name or command>

-V

A string is written to the standard output. This string specifies how the shell interprets the name in the command_name operand in the current shell environment. Although the format of the string is not specified, it nevertheless defines which of the following categories command_name belongs to. The associated information is also defined:

  • Commands, regular built-in commands and implementation-specific functions which are found via the PATH variable are identified as such. In this case the string contains the absolute path name.

  • Other shell functions are identified as functions.

  • Aliases are identified as aliases. The definitions are specified in the string.

  • Special built-in commands are identified as special built-in commands.

  • Regular built-in commands which cannot be accessed via the definition in the PATH variable are identified as regular built-in commands. (The term "regular" is optional.)

  • Reserved shell terms are identified as reserved shell terms.

The standard output is formatted as follows: "%s\n", <undefined>

command_name

The name of a command or of a special built-in command.

Field of application

The command search sequence can be used to disable functions, regular built-in commands and the path search sequence. This is necessary so that functions which share the same name for a command are able to call this command (instead of a recursive function call).

The default system path is available via getconf. Since under certain circumstances PATH must have been set before getconf is called, the following options are available:

command -p getconf _CS_PATH

Occasionally it can be desirable to suppress the properties of special built-in commands. For example:

command exec > non_writable_file

This input does not cause a non-interactive procedure to abort. The output status can be queried by the procedure.

Return code 127 is used for command, env, nohup, time and xargs if an error occurs or if command_name could not be found. This enables applications to determine whether it was impossible to find a command or whether the command was terminated with an error. The value 127 was selected because it is not generally used for any other meaning. Low values are generally used for "normal error conditions". Values higher than 128 may be mistaken 

for termination resulting from signal reception. For similar reasons, the value 126 was selected to indicate that although the command was found, it could not be called. Many procedures generate informative error messages which differentiate between 126 and 127. This distinction between return codes 126 and 127 is based on experience of the Korn shell which handles these codes as follows: 127 is used if all attempts to execute the command exec fail with [ENOENT]; 126 is used if an attempt to execute exec fails for any other reason.

Since with the options -v and -V the output for command is generated in accordance with the current shell environment, command is generally provided as a regular built-in shell command. If the call is issued in a subshell or a special run environment such as:

(PATH=foo command -v)
nohup command -v


this does not always yield correct results. Thus, for example, in certain run environments most implementations are unable to recognize alias names, functions or special built-in commands if the call is made via the nohup or exec functions.

Two types of regular built-in commands may be present in a system. Both are described separately under command. The description of a command search allows for the implementation of a default command as a regular built-in command provided that this is read at the correct position in a PATH search. Thus, for example, the result of command -v true may be the path name /bin/true or a similar path name. Other, implementation-specific commands which are not defined in this documentation may also occur as built-in commands. No path name is allocated to such commands. The output is identified as that of (regular) built-in commands. In no case can applications execute the command exec, use nohup, disable the output by means of another PATH etc.


Locale

The following environment variables affect the execution of command:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

PATH

Determines the search path used during the command search, except where a default value has been set with -p.

Example 1

A version of cd is generated which outputs the current directory precisely once:

cd() {
       command cd "$@" >/dev/null
       pwd
      } 

Example 2

A "safe shell procedure" is started in which the procedure cannot be influenced by the parent:

IFS='
'
#   The preceding value should be <space><tab><newline>.
#   IFS is set to the default value.
\unalias -a
#   All possible aliases are reset.
#   unalias is quoted to prevent the use of
#   any alias.
unset -f command
#   The command may not be a user function.
PATH="$(command -p getconf _CS_PATH):$PATH"
# Introduce PATH prefix.
#   ...

Provided that the access permissions for the directories called by PATH are set correctly, then at this point the procedure can make sure that the called commands actually correspond to the commands which are to be addressed. Great care is taken here since it is assumed that implementation-specific extensions may be present which permit user functions when called. Although this possibility is not described in this documentation, such an extension is perfectly possible. For example the variable ENV precedes the call to a procedure with a user-defined start procedure. Such a procedure might, for example, define functions which affect the application.

See also

sh, type