command (1)
PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.NAME
command --- execute a simple commandSYNOPSIS
command [-p] command_name [argument...] command [-p][-v|-V] command_name
DESCRIPTION
The command utility shall cause the shell to treat the arguments as a simple command, suppressing the shell function lookup that is described in Section 2.9.1.1, Command Search and Execution, item 1b. If the command_name is the same as the name of one of the special built-in utilities, the special properties in the enumerated list at the beginning of Section 2.14, Special Built-In Utilities shall not occur. In every other respect, if command_name is not the name of a function, the effect of command (with no options) shall be the same as omitting command. When the -v or -V option is used, the command utility shall provide information concerning how a command name is interpreted by the shell.OPTIONS
The command utility shall conform to the Base Definitions volume of POSIX.1-2008, Section 12.2, Utility Syntax Guidelines. The following options shall be supported:- -p
- Perform the command search using a default value for PATH that is guaranteed to find all of the standard utilities.
- -v
-
Write a string to standard output that indicates the pathname or command
that will be used by the shell, in the current shell execution environment
(see
Section 2.12, Shell Execution Environment),
to invoke
command_name,
but do not invoke
command_name.
-
- *
- Utilities, regular built-in utilities, command_names including a <slash> character, and any implementation-defined functions that are found using the PATH variable (as described in Section 2.9.1.1, Command Search and Execution), shall be written as absolute pathnames.
- *
- Shell functions, special built-in utilities, regular built-in utilities not associated with a PATH search, and shell reserved words shall be written as just their names.
- *
- An alias shall be written as a command line that represents its alias definition.
- *
- Otherwise, no output shall be written and the exit status shall reflect that the name was not found.
-
- -V
-
Write a string to standard output that indicates how the name given in the
command_name
operand will be interpreted by the shell, in the current shell
execution environment (see
Section 2.12, Shell Execution Environment),
but do not invoke
command_name.
Although the format of this string is unspecified, it shall indicate in
which of the following categories
command_name
falls and shall include the information stated:
-
- *
- Utilities, regular built-in utilities, and any implementation-defined functions that are found using the PATH variable (as described in Section 2.9.1.1, Command Search and Execution), shall be identified as such and include the absolute pathname in the string.
- *
- Other shell functions shall be identified as functions.
- *
- Aliases shall be identified as aliases and their definitions included in the string.
- *
- Special built-in utilities shall be identified as special built-in utilities.
- *
- Regular built-in utilities not associated with a PATH search shall be identified as regular built-in utilities. (The term ``regular'' need not be used.)
- *
- Shell reserved words shall be identified as reserved words.
-
OPERANDS
The following operands shall be supported:- argument
- One of the strings treated as an argument to command_name.
- command_name
-
The name of a utility or a special built-in utility.
STDIN
Not used.INPUT FILES
None.ENVIRONMENT VARIABLES
The following environment variables shall affect the execution of command:- LANG
- Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1-2008, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
- 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-byte as opposed to multi-byte characters in arguments).
- LC_MESSAGES
-
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. - NLSPATH
- Determine the location of message catalogs for the processing of LC_MESSAGES.
- PATH
- Determine the search path used during the command search described in Section 2.9.1.1, Command Search and Execution, except as described under the -p option.
ASYNCHRONOUS EVENTS
Default.STDOUT
When the -v option is specified, standard output shall be formatted as:
-
"%s\n", <pathname or command>
-
"%s\n", <unspecified>
STDERR
The standard error shall be used only for diagnostic messages.OUTPUT FILES
None.EXTENDED DESCRIPTION
None.EXIT STATUS
When the -v or -V options are specified, the following exit values shall be returned:- 0
- Successful completion.
- >0
- The command_name could not be found or an error occurred. Otherwise, the following exit values shall be returned:
- 126
- The utility specified by command_name was found but could not be invoked.
- 127
- An error occurred in the command utility or the utility specified by command_name could not be found. Otherwise, the exit status of command shall be that of the simple command specified by the arguments to command.
CONSEQUENCES OF ERRORS
Default.The following sections are informative.
APPLICATION USAGE
The order for command search allows functions to override regular built-ins and path searches. This utility is necessary to allow functions that have the same name as a utility to call the utility (instead of a recursive call to the function). The system default path is available using getconf; however, since getconf may need to have the PATH set up before it can be called itself, the following can be used:
-
command -p getconf PATH
-
command exec > unwritable-file
-
(PATH=foo command -v) nohup command -v
EXAMPLES
- 1.
-
Make a version of
cd
that always prints out the new working directory exactly once:
-
-
cd() { command cd "$@" >/dev/null pwd }
-
-
- 2.
-
Start off a ``secure shell script'' in which the script avoids
being spoofed by its parent:
-
-
IFS=' ' # The preceding value should be <space><tab><newline>. # Set IFS to its default value. \unalias -a # Unset all possible aliases. # Note that unalias is escaped to prevent an alias # being used for unalias. unset -f command # Ensure command is not a user function. PATH="$(command -p getconf PATH):$PATH" # Put on a reliable PATH prefix. # ...
-
-
RATIONALE
Since command is a regular built-in utility it is always found prior to the PATH search. There is nothing in the description of command that implies the command line is parsed any differently from that of any other simple command. For example:
-
command a | b ; c
- *
- The removal of exportable functions made the special precedence of a special built-in unnecessary.
- *
-
A special built-in has special properties (see
Section 2.14, Special Built-In Utilities)
that were inappropriate for invoking other utilities. For example, two
commands such as:
-
-
date > unwritable-file command date > unwritable-file
-
-
FUTURE DIRECTIONS
None.SEE ALSO
Section 2.9.1.1, Command Search and Execution, Section 2.12, Shell Execution Environment, Section 2.14, Special Built-In Utilities, sh, type The Base Definitions volume of POSIX.1-2008, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines The System Interfaces volume of POSIX.1-2008, execCOPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, Copyright (C) 2013 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at www.unix.org/online.html .Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see www.kernel.org/doc/man-pages/reporting_bugs.html .