I am using posh to test my shell script that I want to run successfully on any POSIX compliant shell. While doing so, I found that the command -v
option is not
See the [UP]
margin code next to the definition of -v
. Per the list of margin code notations (emphasis added):
[UP] User Portability
The functionality described is optional.
Where applicable, utilities are marked with the UP margin legend in the SYNOPSIS section. Where additional semantics apply to a utility, the material is identified by use of the UP margin legend.
Thus, it's black-letter POSIX: This functionality is optional.
It depends on which version of POSIX they're compatible with. In the POSIX 2004 material, command has the -v
and -V
options in an optional part of the standard — the 'User Portability' subset.
POSIX 2008 (as amended in 2013) does not mark any part of the specification of command with 'User Portability' subset:
Synopsis
command [-p] command_name [argument...] command [-p][-v|-V] command_name
DESCRIPTION
The
command
utility shall cause the shell to treat the arguments as a simple command, suppressing the shell function lookup that is described in Command Search and Execution, item 1b.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 Special Built-In Utilities shall not occur. In every other respect, ifcommand_name
is not the name of a function, the effect ofcommand
(with no options) shall be the same as omittingcommand
.When the
-v
or-V
option is used, thecommand
utility shall provide information concerning how a command name is interpreted by the shell.
There are no optional flags listed in the 2008/2013 version. In the older (2004) standard, the -v
and -V
options were part of the 'user portability' subset, not part of the core.
So, if they want to conform to the standard that is more than a decade old, there's no need for -v
or -V
; if they want to conform to the current standard (which is more than 5 years old), these options should be supported.