xref: /titanic_52/usr/src/man/man1/command.1 (revision c0e7977a434048a8bc7386ea0e8befaa77a646cf)
te
Copyright (c) 1992, X/Open Company Limited All Rights Reserved
Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
http://www.opengroup.org/bookstore/.
The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions 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 http://www.opengroup.org/unix/online.html.
This notice shall appear on any product containing this material.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
COMMAND 1 "Apr 8, 2008"
NAME
command - execute a simple command
SYNOPSIS

command [-p] command_name [argument]...

command [-v | -V] command_name
"ksh93"

command [-pvxV] [command_name [argument...]]
DESCRIPTION

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.

"ksh93"

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

OPTIONS

The following options are supported by /usr/bin/command: -p

Performs the command search using a default value for PATH that is guaranteed to find all of the standard utilities.

-v

Writes a string to standard output that indicates the path or command that is be used by the shell, in the current shell execution environment to invoke command_name, but does not invoke command_name.

Utilities, regular built-in utilities, command_names including a slash character, and any implementation-provided functions that are found using the PATH variable is written as absolute path names.

Shell functions, special built-in utilities, regular built-in utilities not associated with a PATH search, and shell reserved words are written as just their names.

An alias is written as a command line that represents its alias definition.

Otherwise, no output is written and the exit status reflects that the name was not found.

-V

Writes a string to standard output that indicates how the name specified in the command_name operand is interpreted by the shell, in the current shell execution environment, but does not invoke command_name. Although the format of this string is unspecified, it indicates in which of the following categories command_name falls and include the information stated:

Utilities, regular built-in utilities, and any implementation-provided functions that are found using the PATH variable is identified as such and include the absolute path name in the string.

Other shell functions is identified as functions.

Aliases are identified as aliases and their definitions are included in the string.

Special built-in utilities are identified as special built-in utilities.

Regular built-in utilities not associated with a PATH search is identified as regular built-in utilities.

Shell reserved words are identified as reserved words.

"ksh93"

The following options are supported by ksh93 command: -p

Causes a default path to be searched rather than the one defined by the value of PATH.

-v

Equivalent to:

whence command [argument ...]
-V

Equivalent to:

whence -v command [argument ...]
-x

If command fails because there are too many arguments, it is invoked multiple times with a subset of the arguments on each invocation. Arguments that occur prior to the first word that expand to multiple arguments and arguments that occur after the last word that expands to multiple arguments are passed on each invocation. The exit status is the maximum invocation exit status.

OPERANDS

The following operands are 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.

EXAMPLES

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.
\eunalias -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.

ENVIRONMENT VARIABLES

See environ(5) for descriptions of the following environment variables that affect the execution of command: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH. PATH

Determine the search path used during the command search, except as described under the -p option.

EXIT STATUS

When the -v or -V options are specified, the following exit values are returned: 0

Successful completion.

>0

The command_name could not be found or an error occurred.

Otherwise, the following exit values are 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 is that of the simple command specified by the arguments to command.

"ksh93"

If command is invoked, the exit status of command is that of command. Otherwise, it is one of the following: 0

command_name completed successfully.

>0

-v or -V has been specified and an error occurred.

126

command_name was found but could not be invoked.

127

command_name could not be found.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Committed
Standard See standards(5).
"ksh93"
ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Uncommitted
SEE ALSO

ksh93(1), sh(1), type(1), whence(1), attributes(5), environ(5), standards(5)