Executes a simple command.
The command command causes the shell to treat the specified command and arguments as a simple command, suppressing shell function lookup.
Normally, when a / (slash) does not precede a command (indicating a specific path), the shell locates a command by searching the following categories:
For example, if there is a function with the same name as a regular built-in, the system uses the function. The command command allows you to call a command that has the same name as a function and get the simple command.
The command -v and command -V commands write to standard output what path name will be used by the shell and how the shell interprets the command type (built-in, function, alias, and so forth). Since the -v and -V flags produce output in relation to the current shell environment, the command command is provided as a Korn shell or POSIX shell regular built-in command. The /usr/bin/command command might not produce correct results, because it is called in a subshell or separate command execution environment,. In the following example the shell is unable to identify aliases, subroutines, or special shell commands:
(PATH=foo command -v)
nohup command -v
Item | Description |
---|---|
-p | Performs the command search using a default value for the PATH environment variable that is finds all of the standard commands. |
-v | Writes to standard output the path name used by the current
shell to invoke the specified command, according to the following
conventions:
If the specified command name cannot be found, no output is written and the exit status returns a >0 value. |
-V | Writes to standard output the command name that will be interpreted
by the current shell environment. Although the format of this output
is unspecified, The output indicates in which of the following categories
the command falls:
|
When the -v or -V flag is specified, the following exit values are returned:
Item | Description |
---|---|
0 | Successful completion. |
>0 | The command specified with the CommandName parameter could not be found or an error occurred. |
When the -v or -V flag is not specified, the following exit values are returned:
Item | Description |
---|---|
126 | The command specified by the CommandName parameter was found but could not be invoked. |
127 | An error occurred in the command command, or the command specified by the CommandName parameter could not be found. |
Otherwise, the command command returns the exit status associated with the command specified by the CommandName parameter.
cd () {
command cd "$@" >/dev/null
pwd
}
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 the PATH environment variable, the script
has the ability to ensure that any command it calls is the intended
one.Item | Description |
---|---|
/usr/bin/ksh | Contains the Korn shell command built-in command. |
/usr/bin/command | Contains the command command. |