command(1) command(1)
NAME
command - execute a simple command
SYNOPSIS
command [-p] commandname [argument ...]
command [-v | -V] commandname
DESCRIPTION
command causes the shell to treat the arguments as a simple command,
suppressing the shell function lookup.
If the commandname is the same as the name of one of the special
built-in commands, the special properties of the special built-in com-
mand will not occur. In every other respect, if commandname is not the
name of a function, the effect of command will be the same as omitting
command.
command also provides information as to how a command name is inter-
preted by the shell. See -v and -V.
OPTIONS
-p Performs the command search using a default value for PATH. All
of the standard commands can be found using these default path-
names.
-v Writes the pathname or command, with which the shell invokes
commandname in its current execution environment, to standard
output.
- Commands, regular built-in commands, command names
(commandname) including a slash character, and all available
functions that can be found using the PATH variable, are writ-
ten as absolute pathnames.
- Shell functions, special built-in commands, and regular
built-in commands that cannot be found using PATH, as well as
reserved words within the shell are written as just simple
names.
- An alias will be written as the alias definition.
- In all other cases, no output is written, and the exit status
will show that the name was not found.
-V Specifies how commandname is interpreted by the shell in its
current execution environment. The output specifies which of the
categories listed below commandname belongs to, and contains the
following information:
Page 1 Reliant UNIX 5.44 Printed 11/98
command(1) command(1)
- Commands, regular built-in commands, and all available func-
tions that can be found using the PATH variable are identified
as such and are written with absolute pathnames.
- Other shell functions are identified as functions.
- Aliases are identified as such, and are written as alias
definitions.
- Special built-in commands are identified as such.
- Regular built-in commands that cannot be found using PATH are
identified as regular built-in commands.
- Reserved words in the shell are identified as reserved words.
argument
Character string treated as an argument to commandname.
commandname
The name of a command or a special built-in command.
ENVIRONMENT VARIABLES
LANG Provides a default value for the internationalization
variables that are unset or null. If LANG is unset or
null, the corresponding default value from the interna-
tionalized environment is used. If one of the interna-
tionalization variables contains an invalid setting, the
command behaves as if none of the variables have been
defined.
LCALL If this variable has been assigned a value, i.e. it is
not a null string, this value overrides the values of all
the other internationalization variables.
LCCTYPE Determines the internationalized environment for the
interpretation of byte sequences as characters (e.g.
single-byte characters as opposed to multi-byte charac-
ters in arguments).
LCMESSAGES Determines the format and contents of error messages. The
internationalized environment specified here is also
valid for informative messages written to standard out-
put.
NLSPATH Determines the position of message catalogs for the pro-
cessing of LCMESSAGES.
PATH Determines the search path used during the command
search, except where a default value has been set with
-p.
Page 2 Reliant UNIX 5.44 Printed 11/98
command(1) command(1)
EXIT STATUS
If one of the options -v or -V is specified, the following exit values
are returned:
0 Successful completion.
>0 commandname could not be invoked or an error occurred.
Otherwise, the following exit values are returned:
126 The command specified by commandname was found, but could not be
invoked.
127 An error occurred in the command or the command specified by
commandname could not be found.
Otherwise, the exit status of commandname is returned.
APPLICATION USAGE
The order for a command search allows functions to override regular
built-in utilities and search paths. command allows functions that
have the same name as a command to invoke the command (instead of a
recursive call to the function).
The system default path can be queried using getconf(1). Since getconf
may need to be invoked itself using PATH, the following call can be
used:
command -p getconf CSPATH
There are some advantages to suppressing the special characteristics
of special built-in commands. In the example below, the abort of a
non-interactive script is suppressed, so that the output status of the
script can be checked.
command exec > unwritable-file
Since the -v and -V options of command produce output in relation to
the current shell execution environment, command is provided as a reg-
ular built-in shell command. If it is called in a subshell or a
separate execution environment, as in the example below, it may pro-
duce incorrect results:
(PATH=foo command -v)
nohup command -v
If, for example, it is called with nohup or exec in a separate execu-
tion environment, most implementations will not be able to identify
aliases, functions or special built-in commands.
Page 3 Reliant UNIX 5.44 Printed 11/98
command(1) command(1)
EXAMPLES
1. A version of cd that outputs the new working directory can be made
as follows:
cd1() {
command cd "$@" >/dev/null
pwd
}
Note: Since cd is a built-in shell command, it must not be rede-
fined according to the X/Open specification. For this reason, the
name "cd" must be changed to "cd1" [cf. sh(1), section Defining a
shell function].
2. A "secure shell script" that cannot be spoofed by its parent pro-
cess can be started as follows:
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 CSPATH):$PATH"
# Put on a reliable PATH prefix.
# ...
Provided that the correct permissions exist for the directories
called by PATH, the script can now ensure that any command it
invokes is the intended one.
NOTES
command exists both as an external command (/usr/bin/command) and as a
built-in shell command in the Korn shell ksh(1). The shell generates a
new process to execute /usr/bin/command.
Some differences in behavior may occur when using command, depending
on which command is being used. The possible differences are not
described specifically.
SEE ALSO
getconf(1), ksh(1), type(1).
Page 4 Reliant UNIX 5.44 Printed 11/98