POSIX shell 中是否需要 `command -v` 选项?豪华是否符合 POSIX?

Is `command -v` option required in a POSIX shell? Is posh compliant with POSIX?

我正在使用 posh 来测试我的 shell 脚本,我想在任何 POSIX 兼容的 shell 上成功 运行。这样做时,我发现 posh 不支持 command -v 选项。 type.

也不是

我了解到 type 不受支持,因为 POSIX 不需要它。 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=397601#10.

对此进行了讨论

"type" is an X/Open extension; note the XSI marking in the POSIX standard. Since it is not required by POSIX or by debian policy, posh doesn't implement it.

http://pubs.opengroup.org/onlinepubs/009695399/utilities/type.html 证实了这一点。请参阅概要中的 [XSI] 保证金代码。

但是我不明白为什么 posh 不支持 command -v 选项。

有人提到 command -vhttps://bugs.debian.org/cgi-bin/bugreport.cgi?bug=218530#131 处是可选的。

And "command -v" is an optional functionality according to http://www.opengroup.org/onlinepubs/009695399/utilities/ just to mention it.

但我无法在 http://pubs.opengroup.org/onlinepubs/009695399/utilities/command.html 确认这一点。你能在这里看到任何表明 -v 选项在 command 中是可选的吗?

如果不是,posh是否不符合POSIX?

请参阅 -v 定义旁边的 [UP] 保证金代码。每 the list of margin code notations(强调):

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

因此,它是 black-letter POSIX:此功能是可选的。

这取决于它们兼容的 POSIX 版本。在 POSIX 2004 material 中,command 在标准的可选部分 — 'User Portability' 子集中有 -v-V 选项。

POSIX 2008(2013年修订)未将command规范的任何部分标记为'User Portability'子集:

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, if command_name is not the name of a function, the effect of command (with no options) shall be the same as omitting command.

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

2008/2013 版本中没有列出可选标志。在旧的 (2004) 标准中,-v-V 选项是 'user portability' 子集的一部分,而不是核心的一部分。

因此,如果他们想要符合已有十多年历史的标准,则不需要 -v-V;如果他们想要符合当前标准(超过 5 年),则应支持这些选项。