COMMAND(1)                 POSIX Programmer's Manual                COMMAND(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       command -- execute a simple command

SSYYNNOOPPSSIISS
       command [[-p]] _c_o_m_m_a_n_d___n_a_m_e [[_a_r_g_u_m_e_n_t...]]

       command [[-p]][[-v|-V]] _c_o_m_m_a_n_d___n_a_m_e

DDEESSCCRRIIPPTTIIOONN
       The _c_o_m_m_a_n_d utility shall cause the shell to treat the arguments as a
       simple command, suppressing the shell function lookup that is described
       in _S_e_c_t_i_o_n _2_._9_._1_._1, _C_o_m_m_a_n_d _S_e_a_r_c_h _a_n_d _E_x_e_c_u_t_i_o_n, item 1b.

       If the _c_o_m_m_a_n_d___n_a_m_e 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 _S_e_c_t_i_o_n _2_._1_4, _S_p_e_c_i_a_l _B_u_i_l_t_-_I_n _U_t_i_l_i_t_i_e_s shall not
       occur. In every other respect, if _c_o_m_m_a_n_d___n_a_m_e is not the name of a
       function, the effect of _c_o_m_m_a_n_d (with no options) shall be the same as
       omitting _c_o_m_m_a_n_d.

       When the --vv or --VV option is used, the _c_o_m_m_a_n_d utility shall provide
       information concerning how a command name is interpreted by the shell.

OOPPTTIIOONNSS
       The _c_o_m_m_a_n_d utility shall conform to the Base Definitions volume of
       POSIX.1-2017, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s.

       The following options shall be supported:

       --pp        Perform the command search using a default value for _P_A_T_H
                 that is guaranteed to find all of the standard utilities.

       --vv        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 _S_e_c_t_i_o_n _2_._1_2, _S_h_e_l_l
                 _E_x_e_c_u_t_i_o_n _E_n_v_i_r_o_n_m_e_n_t), to invoke _c_o_m_m_a_n_d___n_a_m_e, but do not
                 invoke _c_o_m_m_a_n_d___n_a_m_e.

                  *  Utilities, regular built-in utilities, _c_o_m_m_a_n_d___n_a_m_es
                     including a <slash> character, and any implementation-
                     defined functions that are found using the _P_A_T_H variable
                     (as described in _S_e_c_t_i_o_n _2_._9_._1_._1, _C_o_m_m_a_n_d _S_e_a_r_c_h _a_n_d
                     _E_x_e_c_u_t_i_o_n), shall be written as absolute pathnames.

                  *  Shell functions, special built-in utilities, regular
                     built-in utilities not associated with a _P_A_T_H 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.

       --VV        Write a string to standard output that indicates how the name
                 given in the _c_o_m_m_a_n_d___n_a_m_e operand will be interpreted by the
                 shell, in the current shell execution environment (see
                 _S_e_c_t_i_o_n _2_._1_2, _S_h_e_l_l _E_x_e_c_u_t_i_o_n _E_n_v_i_r_o_n_m_e_n_t), but do not invoke
                 _c_o_m_m_a_n_d___n_a_m_e.  Although the format of this string is
                 unspecified, it shall indicate in which of the following
                 categories _c_o_m_m_a_n_d___n_a_m_e falls and shall include the
                 information stated:

                  *  Utilities, regular built-in utilities, and any
                     implementation-defined functions that are found using the
                     _P_A_T_H variable (as described in _S_e_c_t_i_o_n _2_._9_._1_._1, _C_o_m_m_a_n_d
                     _S_e_a_r_c_h _a_n_d _E_x_e_c_u_t_i_o_n), 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 _P_A_T_H
                     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.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _a_r_g_u_m_e_n_t  One of the strings treated as an argument to _c_o_m_m_a_n_d___n_a_m_e.

       _c_o_m_m_a_n_d___n_a_m_e
                 The name of a utility or a special built-in utility.

SSTTDDIINN
       Not used.

IINNPPUUTT FFIILLEESS
       None.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of
       _c_o_m_m_a_n_d:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2017, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

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

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

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

       _P_A_T_H      Determine the search path used during the command search
                 described in _S_e_c_t_i_o_n _2_._9_._1_._1, _C_o_m_m_a_n_d _S_e_a_r_c_h _a_n_d _E_x_e_c_u_t_i_o_n,
                 except as described under the --pp option.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       When the --vv option is specified, standard output shall be formatted as:


           "%s\n", <_p_a_t_h_n_a_m_e _o_r _c_o_m_m_a_n_d>

       When the --VV option is specified, standard output shall be formatted as:


           "%s\n", <_u_n_s_p_e_c_i_f_i_e_d>

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       When the --vv or --VV options are specified, the following exit values
       shall be returned:

        0    Successful completion.

       >0    The _c_o_m_m_a_n_d___n_a_m_e could not be found or an error occurred.

       Otherwise, the following exit values shall be returned:

       126   The utility specified by _c_o_m_m_a_n_d___n_a_m_e was found but could not be
             invoked.

       127   An error occurred in the _c_o_m_m_a_n_d utility or the utility specified
             by _c_o_m_m_a_n_d___n_a_m_e could not be found.

       Otherwise, the exit status of _c_o_m_m_a_n_d shall be that of the simple
       command specified by the arguments to _c_o_m_m_a_n_d.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       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 _g_e_t_c_o_n_f; however, since
       _g_e_t_c_o_n_f may need to have the _P_A_T_H set up before it can be called
       itself, the following can be used:


           command -p getconf PATH

       There are some advantages to suppressing the special characteristics of
       special built-ins on occasion. For example:


           command exec > _u_n_w_r_i_t_a_b_l_e_-_f_i_l_e

       does not cause a non-interactive script to abort, so that the output
       status can be checked by the script.

       The _c_o_m_m_a_n_d, _e_n_v, _n_o_h_u_p, _t_i_m_e, and _x_a_r_g_s utilities have been specified
       to use exit code 127 if an error occurs so that applications can
       distinguish ``failure to find a utility'' from ``invoked utility exited
       with an error indication''. The value 127 was chosen because it is not
       commonly used for other meanings; most utilities use small values for
       ``normal error conditions'' and the values above 128 can be confused
       with termination due to receipt of a signal. The value 126 was chosen
       in a similar manner to indicate that the utility could be found, but
       not invoked. Some scripts produce meaningful error messages
       differentiating the 126 and 127 cases. The distinction between exit
       codes 126 and 127 is based on KornShell practice that uses 127 when all
       attempts to _e_x_e_c the utility fail with [[EENNOOEENNTT]], and uses 126 when any
       attempt to _e_x_e_c the utility fails for any other reason.

       Since the --vv and --VV options of _c_o_m_m_a_n_d produce output in relation to
       the current shell execution environment, _c_o_m_m_a_n_d is generally provided
       as a shell regular built-in. If it is called in a subshell or separate
       utility execution environment, such as one of the following:


           (PATH=foo command -v)
            nohup command -v

       it does not necessarily produce correct results. For example, when
       called with _n_o_h_u_p or an _e_x_e_c function, in a separate utility execution
       environment, most implementations are not able to identify aliases,
       functions, or special built-ins.

       Two types of regular built-ins could be encountered on a system and
       these are described separately by _c_o_m_m_a_n_d.  The description of command
       search in _S_e_c_t_i_o_n _2_._9_._1_._1, _C_o_m_m_a_n_d _S_e_a_r_c_h _a_n_d _E_x_e_c_u_t_i_o_n allows for a
       standard utility to be implemented as a regular built-in as long as it
       is found in the appropriate place in a _P_A_T_H search. So, for example,
       _c_o_m_m_a_n_d --vv _t_r_u_e might yield //bbiinn//ttrruuee or some similar pathname. Other
       implementation-defined utilities that are not defined by this volume of
       POSIX.1-2017 might exist only as built-ins and have no pathname
       associated with them. These produce output identified as (regular)
       built-ins. Applications encountering these are not able to count on
       _e_x_e_cing them, using them with _n_o_h_u_p, overriding them with a different
       _P_A_T_H, and so on.

EEXXAAMMPPLLEESS
        1. Make a version of _c_d 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.

               #    ...

           At this point, given correct permissions on the directories called
           by _P_A_T_H, 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 may be present that would
           allow user functions to exist when it is invoked; this capability
           is not specified by this volume of POSIX.1-2017, but it is not
           prohibited as an extension. For example, the _E_N_V variable precedes
           the invocation of the script with a user start-up script. Such a
           script could define functions to spoof the application.

RRAATTIIOONNAALLEE
       Since _c_o_m_m_a_n_d is a regular built-in utility it is always found prior to
       the _P_A_T_H search.

       There is nothing in the description of _c_o_m_m_a_n_d that implies the command
       line is parsed any differently from that of any other simple command.
       For example:


           command a | b ; c

       is not parsed in any special way that causes ''||'' or '';;'' to be treated
       other than a pipe operator or <semicolon> or that prevents function
       lookup on bb or cc.

       The _c_o_m_m_a_n_d utility is somewhat similar to the Eighth Edition shell
       _b_u_i_l_t_i_n command, but since _c_o_m_m_a_n_d also goes to the file system to
       search for utilities, the name _b_u_i_l_t_i_n would not be intuitive.

       The _c_o_m_m_a_n_d utility is most likely to be provided as a regular built-
       in. It is not listed as a special built-in for the following reasons:

        *  The removal of exportable functions made the special precedence of
           a special built-in unnecessary.

        *  A special built-in has special properties (see _S_e_c_t_i_o_n _2_._1_4,
           _S_p_e_c_i_a_l _B_u_i_l_t_-_I_n _U_t_i_l_i_t_i_e_s) that were inappropriate for invoking
           other utilities. For example, two commands such as:


               date > _u_n_w_r_i_t_a_b_l_e_-_f_i_l_e

               command date > _u_n_w_r_i_t_a_b_l_e_-_f_i_l_e

           would have entirely different results; in a non-interactive script,
           the former would continue to execute the next command, the latter
           would abort. Introducing this semantic difference along with
           suppressing functions was seen to be non-intuitive.

       The --pp option is present because it is useful to be able to ensure a
       safe path search that finds all the standard utilities. This search
       might not be identical to the one that occurs through one of the _e_x_e_c
       functions (as defined in the System Interfaces volume of POSIX.1-2017)
       when _P_A_T_H is unset. At the very least, this feature is required to
       allow the script to access the correct version of _g_e_t_c_o_n_f so that the
       value of the default path can be accurately retrieved.

       The _c_o_m_m_a_n_d --vv and --VV options were added to satisfy requirements from
       users that are currently accomplished by three different historical
       utilities: _t_y_p_e in the System V shell, _w_h_e_n_c_e in the KornShell, and
       _w_h_i_c_h in the C shell. Since there is no historical agreement on how and
       what to accomplish here, the POSIX _c_o_m_m_a_n_d utility was enhanced and the
       historical utilities were left unmodified.  The C shell _w_h_i_c_h merely
       conducts a path search. The KornShell _w_h_e_n_c_e is more elaborate--in
       addition to the categories required by POSIX, it also reports on
       tracked aliases, exported aliases, and undefined functions.

       The output format of --VV was left mostly unspecified because human users
       are its only audience.  Applications should not be written to care
       about this information; they can use the output of --vv to differentiate
       between various types of commands, but the additional information that
       may be emitted by the more verbose --VV is not needed and should not be
       arbitrarily constrained in its verbosity or localization for
       application parsing reasons.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._9_._1_._1, _C_o_m_m_a_n_d _S_e_a_r_c_h _a_n_d _E_x_e_c_u_t_i_o_n, _S_e_c_t_i_o_n _2_._1_2, _S_h_e_l_l
       _E_x_e_c_u_t_i_o_n _E_n_v_i_r_o_n_m_e_n_t, _S_e_c_t_i_o_n _2_._1_4, _S_p_e_c_i_a_l _B_u_i_l_t_-_I_n _U_t_i_l_i_t_i_e_s, _s_h,
       _t_y_p_e

       The Base Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

       The System Interfaces volume of POSIX.1-2017, _e_x_e_c

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  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 http://www.opengroup.org/unix/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
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                           COMMAND(1)
