COMMAND(1) | User Commands | COMMAND(1) |
command - execute a simple command
command [-p] command_name [argument]...
command [-v | -V] command_name
command [-pvxV] [command_name [argument...]]
The command utility causes the shell to treat the arguments as a simple command, suppressing the shell function lookup.
If the command_name is the same as the name of one of the special built-in utilities, the special properties do not occur. In every other respect, if command_name is not the name of a function, the effect of command (with no options) are the same as omitting command.
The command utility also provides information concerning how a command name is interpreted by the shell. See -v and -V.
Without the -v or -V option, command executes command_name with arguments specified by argument, suppressing the shell function lookup that normally occurs. In addition, if command is a special built-in command, the special properties are removed so that failures do not cause the script that executes it to terminate.
If the -v or -V options are specified, command is equivalent to whence(1).
The following options are supported by /usr/bin/command:
-p
-v
-V
The following options are supported by ksh93 command:
-p
-v
whence command [argument ...]
-V
whence -v command [argument ...]
-x
The following operands are supported:
argument
command_name
Example 1 Making a Version of cd That Always Prints Out the New Working Directory
The following example takes a version of cd that always prints out the new working directory exactly once:
cd() { command cd "$@" >/dev/null pwd }
Example 2 Starting Off a secure shell script in Which the Script Avoids Being Spoofed by Its Parent
The following example starts 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 _CS_PATH):$PATH" # Put on a reliable PATH prefix. # ...
At this point, given correct permissions on the directories called by PATH, the script has the ability to ensure that any utility it calls is the intended one. It is being very cautious because it assumes that implementation extensions can be present that would allow user functions to exist when it is invoked. This capability is not specified by this document, but it is not prohibited as an extension. For example, the ENV variable precedes the invocation of the script with a user startup script. Such a script could define functions to spoof the application.
See environ(7) for descriptions of the following environment variables that affect the execution of command: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH.
PATH
When the -v or -V options are specified, the following exit values are returned:
0
>0
Otherwise, the following exit values are returned:
126
127
Otherwise, the exit status of command is that of the simple command specified by the arguments to command.
If command is invoked, the exit status of command is that of command. Otherwise, it is one of the following:
0
>0
126
127
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Committed |
Standard | See standards(7). |
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
Interface Stability | Uncommitted |
ksh93(1), sh(1), type(1), whence(1), attributes(7), environ(7), standards(7)
April 8, 2008 | OmniOS |