COMMAND(1POSIX)
๐ฆ COMMAND(1POSIX) ๐ฆ
okay bestie, gather round โ this is the command page from the POSIX Programmer's Manual ๐ and it's giving essential. It's literally a whole manual page for one lil utility, and she's iconic for it.
โจ PROLOG โจ
So like, this manual page is part of the POSIX Programmer's Manual ๐. Heads up tho: the Linux implementation of this interface may differ (bestie, consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux at all. ๐ Not me finding out the hard way.
๐ NAME ๐
command โ execute a simple command. That's the whole vibe. Periodt. ๐
๐ธ SYNOPSIS ๐ธ
command [-p] command_name [argument...]
command [-p][-v|-V] command_name
two whole forms, she's versatile like that โจ
๐ซถ DESCRIPTION ๐ซถ
okay so here's the tea โ โ the command utility shall cause the shell to treat the arguments as a simple command, suppressing the shell function lookup that is described in Section 2.9.1.1, Command Search and Execution, item 1b. Like, we're skipping that step entirely, no cap.
If the command_name 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 Section 2.14, Special Built-In Utilities shall not occur. ๐ In every other respect, if command_name is not the name of a function, the effect of command (with no options) shall be the same as omitting command. So basically, no options = it's just vibing and doing nothing extra.
When the -v or -V option is used, the command utility shall provide information concerning how a command name is interpreted by the shell. it's giving "who are you really" energy ๐
๐ OPTIONS ๐
The command utility shall conform to the Base Definitions volume of POSIX.1โ2017, Section 12.2, Utility Syntax Guidelines. Slay, she follows the rules.
The following options shall be supported:
-pโ Perform the command search using a default value forPATHthat is guaranteed to find all of the standard utilities. it's the "don't worry, I got you" flag ๐ซถ-vโ 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 Section 2.12, Shell Execution Environment), to invokecommand_name, but do not invokecommand_name. she tells you, she doesn't do it. respectful queen.- Utilities, regular built-in utilities,
command_names including a<slash>character, and any implementation-defined functions that are found using thePATHvariable (as described in Section 2.9.1.1, Command Search and Execution), shall be written as absolute pathnames. ๐ฃ๏ธ - Shell functions, special built-in utilities, regular built-in utilities not associated with a
PATHsearch, 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. ๐ nothing? she's not there, bestie.
- Utilities, regular built-in utilities,
-Vโ Write a string to standard output that indicates how the name given in thecommand_nameoperand will be interpreted by the shell, in the current shell execution environment (see Section 2.12, Shell Execution Environment), but do not invokecommand_name. Although the format of this string is unspecified, it shall indicate in which of the following categoriescommand_namefalls and shall include the information stated:- Utilities, regular built-in utilities, and any implementation-defined functions that are found using the
PATHvariable (as described in Section 2.9.1.1, Command Search and Execution), 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
PATHsearch shall be identified as regular built-in utilities. (The term ``regular'' need not be used.) ๐ - Shell reserved words shall be identified as reserved words. ๐
- Utilities, regular built-in utilities, and any implementation-defined functions that are found using the
so -v gives you the short answer and -V gives you the whole paragraph with the category name in it. choose your fighter. โจ
๐ OPERANDS ๐
The following operands shall be supported:
argumentโ One of the strings treated as an argument tocommand_name. like, the lil extras you hand over ๐ซถcommand_nameโ The name of a utility or a special built-in utility. the main character, obviously ๐
๐ STDIN ๐
Not used. she's not reading your keyboard today, bestie.
๐ฆ INPUT FILES ๐ฆ
None. nada. zero. zip. ๐
๐ ENVIRONMENT VARIABLES ๐
The following environment variables shall affect the execution of command:
LANGโ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1โ2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) ๐LC_ALLโ If set to a non-empty string value, override the values of all the other internationalization variables. she overrides EVERYONE. main character energy fr.LC_CTYPEโ 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). ๐คLC_MESSAGESโ 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. ๐ฌNLSPATHโ Determine the location of message catalogs for the processing ofLC_MESSAGES. ๐PATHโ Determine the search path used during the command search described in Section 2.9.1.1, Command Search and Execution, except as described under the-poption. except when-psays otherwise, iykyk
โญ ASYNCHRONOUS EVENTS โญ
Default. she's chill like that.
๐ธ STDOUT ๐ธ
When the -v option is specified, standard output shall be formatted as:
"%s\n", <pathname or command>
When the -V option is specified, standard output shall be formatted as:
"%s\n", <unspecified>
yes bestie, -V literally says unspecified. that's the whole format. iconic honestly.
๐ STDERR ๐
The standard error shall be used only for diagnostic messages. just the lil "hey something's off" notes ๐ฌ
๐ซถ OUTPUT FILES ๐ซถ
None. ๐ณ๏ธ
๐ EXTENDED DESCRIPTION ๐
None. literally nothing here, not even a crumb.
๐ EXIT STATUS ๐
When the -v or -V options are specified, the following exit values shall be returned:
0โ Successful completion. ๐>0โ Thecommand_namecould not be found or an error occurred. ๐ญ
Otherwise, the following exit values shall be returned:
126โ The utility specified bycommand_namewas found but could not be invoked. found her but couldn't get her to come out ๐127โ An error occurred in thecommandutility or the utility specified bycommand_namecould not be found. ๐
Otherwise, the exit status of command shall be that of the simple command specified by the arguments to command. so it just passes the vibe along, no cap.
๐ง CONSEQUENCES OF ERRORS ๐ง
Default. โจ
The following sections are informative.
๐ฅ APPLICATION USAGE ๐ฅ
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). like, without this you'd just call yourself forever and that's a whole spiral bestie ๐ญ
The system default path is available using getconf; however, since getconf may need to have the PATH 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 > unwritable-file
does not cause a non-interactive script to abort, so that the output status can be checked by the script. so the script lives to check the status, she doesn't just โจperishโจ
The command, env, nohup, time, and xargs 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 exec the utility fail with [ENOENT], and uses 126 when any attempt to exec the utility fails for any other reason. so 127 = "who? never heard of her" and 126 = "I know her but she won't pick up the phone". the lore goes deep fr fr ๐
Since the -v and -V options of command produce output in relation to the current shell execution environment, command 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 nohup or an exec function, in a separate utility execution environment, most implementations are not able to identify aliases, functions, or special built-ins. so like, in a subshell she loses the plot a lil bit. not her fault, it's the environment ๐
Two types of regular built-ins could be encountered on a system and these are described separately by command. The description of command search in Section 2.9.1.1, Command Search and Execution 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 PATH search. So, for example, command -v true might yield /bin/true 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 execing them, using them with nohup, overriding them with a different PATH, and so on. basically: some utilities have a home address, some are just... always around. you can't mail them anything. ๐ ๐ซ
and that's part one bestie, there's more coming so don't go anywhere ๐โจ
๐ธ EXAMPLES ๐ธ
Bestie, here's the tea, let's actually do stuff:
- Make a version of
cdthat always prints out the new working directory exactly once:
cd() {
command cd "$@" >/dev/null
pwd
}
- 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 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 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 ENV variable precedes the invocation of the script with a user start-up script. Such a script could define functions to spoof the application ๐ญ
๐ญ RATIONALE ๐ญ
Since command is a regular built-in utility it is always found prior to the PATH search. No cap โจ
There is nothing in the description of command that implies the command line is parsed any differently from that of any other simple command. Like, 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 b or c. The vibes are just normal command vibes, fr fr.
The command utility is somewhat similar to the Eighth Edition shell builtin command, but since command also goes to the file system to search for utilities, the name builtin would not be intuitive. It's giving "we chose the name for a reason" ๐
The command 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 Section 2.14, Special Built-In Utilities) that were inappropriate for invoking other utilities. For example, two commands such as:
date > unwritable-file
command date > unwritable-file
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. Like the way these two LOOK identical but behave completely differently? iconic but also terrifying ๐
The -p 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 exec functions (as defined in the System Interfaces volume of POSIX.1โ2017) when PATH is unset. At the very least, this feature is required to allow the script to access the correct version of getconf so that the value of the default path can be accurately retrieved. Lowkey essential ๐
The command -v and -V options were added to satisfy requirements from users that are currently accomplished by three different historical utilities: type in the System V shell, whence in the KornShell, and which in the C shell. Since there is no historical agreement on how and what to accomplish here, the POSIX command utility was enhanced and the historical utilities were left unmodified. The C shell which merely conducts a path search. The KornShell whence is more elaborateโin addition to the categories required by POSIX, it also reports on tracked aliases, exported aliases, and undefined functions. History really said "everyone do it differently" and POSIX said "bet, I'll do it once" ๐ซถ
The output format of -V 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 -v to differentiate between various types of commands, but the additional information that may be emitted by the more verbose -V is not needed and should not be arbitrarily constrained in its verbosity or localization for application parsing reasons.
Okay bestie, real talk: do not parse-Voutput in your scripts. It's for human eyeballs only. Use-vif you must. Periodt ๐
๐ฎ FUTURE DIRECTIONS ๐ฎ
None.
Not a single one. She said "no thoughts, head empty" and honestly? Respect ๐ง
๐ SEE ALSO ๐
- Section 2.9.1.1, Command Search and Execution, Section 2.12, Shell Execution Environment, Section 2.14, Special Built-In Utilities,
sh,type - The Base Definitions volume of POSIX.1โ2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
- The System Interfaces volume of POSIX.1โ2017,
exec
๐ COPYRIGHT ๐
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 .
And that's the whole page, bestie!! ๐ This one came from IEEE/The Open Group, dated 2017, and the page itself is COMMAND(1POSIX). Go forth and command responsibly, you absolute main character ๐โจ
๐ฆ where this page comes from
- debian bookworm: manpages-posix 2017a-2 ยท Other
- debian trixie: manpages-posix 2017a-2 ยท Other
- ubuntu jammy: manpages-posix 2017a-2 ยท Other
- ubuntu noble: manpages-posix 2017a-2 ยท Other
- ubuntu resolute: manpages-posix 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms